Fix for build issue - ConcurrentNodeServiceTest

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4851 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2007-01-16 17:32:07 +00:00
parent 516471381d
commit b15a708086
5 changed files with 76 additions and 25 deletions

View File

@@ -152,9 +152,6 @@ public class ConcurrentNodeServiceTest extends TestCase
} }
} }
// Make sure there is no pending commit we just hit
Thread.sleep(20000);
SearchService searcher = (SearchService) ctx.getBean(ServiceRegistry.SEARCH_SERVICE.getLocalName()); SearchService searcher = (SearchService) ctx.getBean(ServiceRegistry.SEARCH_SERVICE.getLocalName());
assertEquals(2 * ((count * repeats) + 1), searcher.selectNodes(rootNodeRef, "/*", null, assertEquals(2 * ((count * repeats) + 1), searcher.selectNodes(rootNodeRef, "/*", null,
getNamespacePrefixReolsver(""), false).size()); getNamespacePrefixReolsver(""), false).size());

View File

@@ -1553,6 +1553,7 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
Field.Index.UN_TOKENIZED, Field.TermVector.NO)); Field.Index.UN_TOKENIZED, Field.TermVector.NO));
doc.add(new Field(attributeName + ".size", Long.toString(contentData.getSize()), Field.Store.NO, doc.add(new Field(attributeName + ".size", Long.toString(contentData.getSize()), Field.Store.NO,
Field.Index.TOKENIZED, Field.TermVector.NO)); Field.Index.TOKENIZED, Field.TermVector.NO));
// TODO: Use the node locale in preferanced to the system locale // TODO: Use the node locale in preferanced to the system locale
Locale locale = contentData.getLocale(); Locale locale = contentData.getLocale();
if (locale == null) if (locale == null)

View File

@@ -184,6 +184,8 @@ public class IndexInfo
private ConcurrentLinkedQueue<String> deleteQueue = new ConcurrentLinkedQueue<String>(); private ConcurrentLinkedQueue<String> deleteQueue = new ConcurrentLinkedQueue<String>();
private ConcurrentLinkedQueue<IndexReader> deletableReaders = new ConcurrentLinkedQueue<IndexReader>();
private Cleaner cleaner = new Cleaner(); private Cleaner cleaner = new Cleaner();
private Thread cleanerThread; private Thread cleanerThread;
@@ -658,6 +660,10 @@ public class IndexInfo
File file = new File(location, INDEX_INFO_DELETIONS); File file = new File(location, INDEX_INFO_DELETIONS);
if (!file.exists()) if (!file.exists())
{ {
if(s_logger.isDebugEnabled())
{
s_logger.debug("No deletions for " + id);
}
return Collections.<NodeRef> emptySet(); return Collections.<NodeRef> emptySet();
} }
DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
@@ -668,6 +674,10 @@ public class IndexInfo
deletions.add(new NodeRef(ref)); deletions.add(new NodeRef(ref));
} }
is.close(); is.close();
if(s_logger.isDebugEnabled())
{
s_logger.debug("There are "+deletions.size()+ " deletions for " + id);
}
return deletions; return deletions;
} }
@@ -1118,7 +1128,7 @@ public class IndexInfo
// Make sure we have set up the reader for the data // Make sure we have set up the reader for the data
// ... and close it so we do not up the ref count // ... and close it so we do not up the ref count
//getReferenceCountingIndexReader(id).close(); getReferenceCountingIndexReader(id).close();
} }
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
@@ -1380,26 +1390,32 @@ public class IndexInfo
private void clearOldReaders() throws IOException private void clearOldReaders() throws IOException
{ {
// Find valid
HashSet<String> valid = new HashSet<String>();
for (String id : indexEntries.keySet())
{
IndexEntry entry = indexEntries.get(id);
if (entry.getStatus().isCommitted())
{
valid.add(id);
}
}
// Find current invalid // Find current invalid
HashSet<String> inValid = new HashSet<String>(); HashSet<String> inValid = new HashSet<String>();
for (String id : referenceCountingReadOnlyIndexReaders.keySet()) for (String id : referenceCountingReadOnlyIndexReaders.keySet())
{ {
if (!valid.contains(id)) if (!indexEntries.containsKey(id))
{ {
if(s_logger.isDebugEnabled())
{
s_logger.debug(id+ " is now INVALID ");
}
inValid.add(id); inValid.add(id);
} }
else
{
if(s_logger.isDebugEnabled())
{
s_logger.debug(id+ " is still part of the index ");
}
}
} }
// Clear invalid // Clear invalid
clearInvalid(inValid);
}
private void clearInvalid(HashSet<String> inValid) throws IOException
{
boolean hasInvalid = false; boolean hasInvalid = false;
for (String id : inValid) for (String id : inValid)
{ {
@@ -1410,6 +1426,7 @@ public class IndexInfo
} }
ReferenceCounting referenceCounting = (ReferenceCounting) reader; ReferenceCounting referenceCounting = (ReferenceCounting) reader;
referenceCounting.setInvalidForReuse(); referenceCounting.setInvalidForReuse();
deletableReaders.add(reader);
hasInvalid = true; hasInvalid = true;
} }
if (hasInvalid) if (hasInvalid)
@@ -1880,6 +1897,25 @@ public class IndexInfo
boolean runnable = true; boolean runnable = true;
while (runnable) while (runnable)
{ {
// Add any closed index readers we were waiting for
HashSet<IndexReader> waiting = new HashSet<IndexReader>();
IndexReader reader;
while ((reader = deletableReaders.poll()) != null)
{
ReferenceCounting refCounting = (ReferenceCounting)reader;
if(refCounting.getReferenceCount() == 0)
{
s_logger.debug("Deleting no longer referenced "+refCounting.getId());
s_logger.debug("... queued delete for "+refCounting.getId());
deleteQueue.add(refCounting.getId());
}
else
{
waiting.add(reader);
}
}
deletableReaders.addAll(waiting);
String id = null; String id = null;
HashSet<String> fails = new HashSet<String>(); HashSet<String> fails = new HashSet<String>();
while ((id = deleteQueue.poll()) != null) while ((id = deleteQueue.poll()) != null)
@@ -2314,7 +2350,7 @@ public class IndexInfo
referenceCounting.setInvalidForReuse(); referenceCounting.setInvalidForReuse();
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
{ {
s_logger.debug("... invalidating sub reader after merge" + id); s_logger.debug("... invalidating sub reader after applying deletions" + id);
} }
} }
} }
@@ -2324,10 +2360,17 @@ public class IndexInfo
{ {
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
{ {
s_logger.debug("... invalidating main index reader after merge"); s_logger.debug("... invalidating main index reader after applying deletions");
} }
((ReferenceCounting) mainIndexReader).setInvalidForReuse(); ((ReferenceCounting) mainIndexReader).setInvalidForReuse();
} }
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("... no main index reader to invalidate after applying deletions");
}
}
mainIndexReader = null; mainIndexReader = null;
} }
@@ -2337,10 +2380,6 @@ public class IndexInfo
{ {
s_logger.debug("...applied deletion for " + id); s_logger.debug("...applied deletion for " + id);
} }
for (String id : invalidIndexes)
{
s_logger.debug("...invalidated index " + id);
}
s_logger.debug("...deleting done"); s_logger.debug("...deleting done");
} }
@@ -2595,8 +2634,13 @@ public class IndexInfo
for (String id : toDelete) for (String id : toDelete)
{ {
indexEntries.remove(id); indexEntries.remove(id);
// Only delete if there is no existing ref counting reader
if (!referenceCountingReadOnlyIndexReaders.containsKey(id))
{
s_logger.debug("... queued delete for "+id);
deleteQueue.add(id); deleteQueue.add(id);
} }
}
dumpInfo(); dumpInfo();
@@ -2656,15 +2700,17 @@ public class IndexInfo
{ {
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
{ {
StringBuilder builder = new StringBuilder();
readWriteLock.writeLock().lock(); readWriteLock.writeLock().lock();
try try
{ {
s_logger.debug(""); builder.append("\n");
s_logger.debug("Entry List"); builder.append("Entry List\n");
for (IndexEntry entry : indexEntries.values()) for (IndexEntry entry : indexEntries.values())
{ {
s_logger.debug(" " + entry.toString()); builder.append(" " + entry.toString()).append("\n");
} }
s_logger.debug(builder.toString());
} }
finally finally
{ {

View File

@@ -27,4 +27,6 @@ public interface ReferenceCounting
public int getReferenceCount(); public int getReferenceCount();
public void setInvalidForReuse() throws IOException; public void setInvalidForReuse() throws IOException;
public String getId();
} }

View File

@@ -122,5 +122,10 @@ public class ReferenceCountingReadOnlyIndexReaderFactory
throw new UnsupportedOperationException("Delete is not supported by read only index readers"); throw new UnsupportedOperationException("Delete is not supported by read only index readers");
} }
public String getId()
{
return id;
}
} }
} }