Author: sannegrinovero
Date: 2010-04-30 17:47:10 -0400 (Fri, 30 Apr 2010)
New Revision: 19332
Added:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/BatchIndexingWorkspace.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Dvd.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SearchIndexerTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/TitleAble.java
Log:
HSEARCH-512 - MassIndexer might associate proxies to two open session
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/BatchIndexingWorkspace.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/BatchIndexingWorkspace.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/BatchIndexingWorkspace.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -54,7 +54,7 @@
private final ThreadPoolExecutor execIdentifiersLoader;
private final ProducerConsumerQueue<List<Serializable>>
fromIdentifierListToEntities;
private final ThreadPoolExecutor execFirstLoader;
- private final ProducerConsumerQueue<Object> fromEntityToAddwork;
+ private final ProducerConsumerQueue<List<?>> fromEntityToAddwork;
private final ThreadPoolExecutor execDocBuilding;
private final int objectLoadingThreadNum;
@@ -105,7 +105,7 @@
//pipelining queues:
this.fromIdentifierListToEntities = new
ProducerConsumerQueue<List<Serializable>>( 1 );
- this.fromEntityToAddwork = new ProducerConsumerQueue<Object>(
objectLoadingThreadNum );
+ this.fromEntityToAddwork = new ProducerConsumerQueue<List<?>>(
objectLoadingThreadNum );
//end signal shared with other instances:
this.endAllSignal = endAllSignal;
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/EntityConsumerLuceneworkProducer.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -25,6 +25,7 @@
package org.hibernate.search.batchindexing;
import java.io.Serializable;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@@ -54,7 +55,7 @@
private static final Logger log = LoggerFactory.make();
- private final ProducerConsumerQueue<Object> source;
+ private final ProducerConsumerQueue<List<?>> source;
private final SessionFactory sessionFactory;
private final Map<Class<?>, DocumentBuilderIndexedEntity<?>>
documentBuilders;
private final MassIndexerProgressMonitor monitor;
@@ -67,7 +68,7 @@
private final BatchBackend backend;
public EntityConsumerLuceneworkProducer(
- ProducerConsumerQueue<Object> entitySource,
+ ProducerConsumerQueue<List<?>> entitySource,
MassIndexerProgressMonitor monitor,
SessionFactory sessionFactory,
CountDownLatch producerEndSignal,
@@ -91,6 +92,9 @@
indexAllQueue( session );
transaction.commit();
}
+ catch (Throwable e) {
+ log.error( "error during batch indexing: ", e );
+ }
finally {
producerEndSignal.countDown();
session.close();
@@ -101,20 +105,22 @@
private void indexAllQueue(Session session) {
try {
for ( int cycle=0; true; cycle++ ) {
- Object take = source.take();
- if ( take == null ) {
+ List<?> takeList = source.take();
+ if ( takeList == null ) {
break;
}
else {
- log.trace( "received an object {}", take );
- //trick to attach the objects to session:
- session.buildLockRequest( LockOptions.NONE ).lock( take );
- index( take, session );
- monitor.documentsBuilt( 1 );
- session.evict( take );
- if ( cycle == CLEAR_PERIOD ) {
- cycle = 0;
- session.clear();
+ log.trace( "received a list of objects to index: {}", takeList );
+ for ( Object take : takeList ) {
+ //trick to attach the objects to session:
+ session.buildLockRequest( LockOptions.NONE ).lock( take );
+ index( take, session );
+ monitor.documentsBuilt( 1 );
+ session.evict( take );
+ if ( cycle == CLEAR_PERIOD ) {
+ cycle = 0;
+ session.clear();
+ }
}
}
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/batchindexing/IdentifierConsumerEntityProducer.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -52,7 +52,7 @@
private static final Logger log = LoggerFactory.make();
private final ProducerConsumerQueue<List<Serializable>> source;
- private final ProducerConsumerQueue<Object> destination;
+ private final ProducerConsumerQueue<List<?>> destination;
private final SessionFactory sessionFactory;
private final CacheMode cacheMode;
private final Class<?> type;
@@ -60,7 +60,7 @@
public IdentifierConsumerEntityProducer(
ProducerConsumerQueue<List<Serializable>> fromIdentifierListToEntities,
- ProducerConsumerQueue<Object> fromEntityToAddwork,
+ ProducerConsumerQueue<List<?>> fromEntityToAddwork,
MassIndexerProgressMonitor monitor,
SessionFactory sessionFactory,
CacheMode cacheMode, Class<?> type) {
@@ -133,9 +133,7 @@
List<?> list = criteria.list();
monitor.entitiesLoaded( list.size() );
session.clear();
- for ( Object obj : list ) {
- destination.put( obj );
- }
+ destination.put( list );
}
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -43,16 +43,21 @@
Session session = openSession();
Transaction transaction = session.beginTransaction();
+ Nation italy = new Nation( "Italy", "IT" );
+ session.persist( italy );
+
AncientBook aeneid = new AncientBook();
aeneid.setTitle( "Aeneid" );
aeneid.getAlternativeTitles().add( "Aeneis" );
aeneid.getAlternativeTitles().add( "Eneide" );
+ aeneid.setFirstPublishedIn( italy );
session.persist( aeneid );
AncientBook commedia = new AncientBook();
commedia.setTitle( "Commedia" );
commedia.getAlternativeTitles().add( "La Commedia" );
commedia.getAlternativeTitles().add( "La Divina Commedia" );
+ commedia.setFirstPublishedIn( italy );
session.persist( commedia );
transaction.commit();
@@ -84,7 +89,8 @@
protected Class<?>[] getMappings() {
return new Class[] {
AncientBook.class,
- Book.class
+ Book.class,
+ Nation.class
};
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/BatchBackendConfigurationTest.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -45,6 +45,7 @@
public void testConfigurationIsRead() throws InterruptedException {
FullTextSessionBuilder fsBuilder = new FullTextSessionBuilder()
.addAnnotatedClass( Book.class )
+ .addAnnotatedClass( Nation.class )
// illegal option:
.setProperty( LuceneBatchBackend.CONCURRENT_WRITERS, "0" )
.build();
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Book.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -25,11 +25,16 @@
package org.hibernate.search.test.batchindexing;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchMode;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
@Indexed
@Entity
@@ -38,6 +43,8 @@
private long id;
private String title;
+
+ private Nation firstPublishedIn;
@Id @GeneratedValue
public long getId() {
@@ -57,4 +64,15 @@
this.title = title;
}
+ @ManyToOne(fetch=FetchType.LAZY,optional=false)
+ @Fetch(FetchMode.SELECT)
+ @IndexedEmbedded
+ public Nation getFirstPublishedIn() {
+ return firstPublishedIn;
+ }
+
+ public void setFirstPublishedIn(Nation firstPublishedIn) {
+ this.firstPublishedIn = firstPublishedIn;
+ }
+
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Dvd.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Dvd.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Dvd.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -25,8 +25,10 @@
package org.hibernate.search.test.batchindexing;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.ManyToOne;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
@@ -35,8 +37,9 @@
@Entity
public class Dvd implements TitleAble {
- public long unusuallyNamedIdentifier;
- public String title;
+ private long unusuallyNamedIdentifier;
+ private String title;
+ private Nation firstPublishedIn;
@Id
@GeneratedValue
@@ -56,5 +59,14 @@
public void setTitle(String title) {
this.title = title;
}
+
+ @ManyToOne(optional=false, fetch=FetchType.EAGER)
+ public Nation getFirstPublishedIn() {
+ return firstPublishedIn;
+ }
+ public void setFirstPublishedIn(Nation firstPublishedIn) {
+ this.firstPublishedIn = firstPublishedIn;
+ }
+
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -43,9 +43,9 @@
*/
public class IndexingGeneratedCorpusTest extends TestCase {
- private final int BOOK_NUM = 300;
- private final int ANCIENTBOOK_NUM = 60;
- private final int DVD_NUM = 200;
+ private final int BOOK_NUM = 600;
+ private final int ANCIENTBOOK_NUM = 120;
+ private final int DVD_NUM = 400;
private SentenceInventor sentenceInventor = new SentenceInventor( 7L, 10000 );
private FullTextSessionBuilder builder;
@@ -59,6 +59,7 @@
.addAnnotatedClass( Book.class )
.addAnnotatedClass( Dvd.class )
.addAnnotatedClass( AncientBook.class )
+ .addAnnotatedClass( Nation.class )
.setProperty( "hibernate.show_sql", "false" ) //too verbose for
this test
.setProperty( LuceneBatchBackend.CONCURRENT_WRITERS, "4" )
.build();
@@ -76,9 +77,15 @@
FullTextSession fullTextSession = builder.openFullTextSession();
try {
Transaction tx = fullTextSession.beginTransaction();
+ fullTextSession.persist( new Nation("Italy", "IT") );
+ tx.commit();
+ tx = fullTextSession.beginTransaction();
for ( int i = 0; i < amount; i++ ) {
TitleAble instance = entityType.newInstance();
instance.setTitle( sentenceInventor.nextSentence() );
+ //to test for HSEARCH-512 we make all entities share some proxy
+ Nation country = (Nation) fullTextSession.load( Nation.class, 1 );
+ instance.setFirstPublishedIn( country );
fullTextSession.persist( instance );
totalEntitiesInDB++;
if ( i % 250 == 249 ) {
Added:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java
(rev 0)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/Nation.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -0,0 +1,76 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.search.test.batchindexing;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+
+@Entity
+public class Nation {
+
+ private Integer id;
+ private String name;
+ private String code;
+
+ public Nation() {}
+
+ public Nation(String name, String code){
+ this.name = name;
+ this.code = code;
+ }
+
+ @Id @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @Field
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Field(index=Index.UN_TOKENIZED)
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+}
+
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SearchIndexerTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SearchIndexerTest.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/SearchIndexerTest.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -51,6 +51,7 @@
.addAnnotatedClass( AncientBook.class )
.addAnnotatedClass( Dvd.class )
.addAnnotatedClass( Book.class )
+ .addAnnotatedClass( Nation.class )
.build();
FullTextSession fullTextSession = ftsb.openFullTextSession();
SearchFactoryImplementor searchFactory = (SearchFactoryImplementor)
fullTextSession.getSearchFactory();
@@ -106,17 +107,22 @@
FullTextSessionBuilder ftsb = new FullTextSessionBuilder()
.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS,
StandardAnalyzer.class.getName() )
.addAnnotatedClass( Dvd.class )
+ .addAnnotatedClass( Nation.class )
.setProperty( Environment.INDEXING_STRATEGY, "manual" )
.build();
{
//creating the test data in database only:
FullTextSession fullTextSession = ftsb.openFullTextSession();
Transaction transaction = fullTextSession.beginTransaction();
+ Nation us = new Nation( "United States of America", "US" );
+ fullTextSession.persist( us );
Dvd dvda = new Dvd();
dvda.setTitle( "Star Trek (episode 96367)" );
+ dvda.setFirstPublishedIn( us );
fullTextSession.save(dvda);
Dvd dvdb = new Dvd();
dvdb.setTitle( "The Trek" );
+ dvdb.setFirstPublishedIn( us );
fullTextSession.save(dvdb);
transaction.commit();
fullTextSession.close();
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/TitleAble.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/TitleAble.java 2010-04-30
19:33:42 UTC (rev 19331)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/TitleAble.java 2010-04-30
21:47:10 UTC (rev 19332)
@@ -29,5 +29,9 @@
public String getTitle();
public void setTitle(String title);
+
+ public void setFirstPublishedIn(Nation firstPublishedIn);
+
+ public Nation getFirstPublishedIn();
}