Author: nzamosenchuk
Date: 2010-06-14 04:44:23 -0400 (Mon, 14 Jun 2010)
New Revision: 2565
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/IndexingQueueTest.java
Log:
EXOJCR-758: AbstractIndex and IndexInfos updated
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -25,6 +25,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.Directory;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +33,8 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.StringReader;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.util.BitSet;
import java.util.Iterator;
@@ -122,7 +125,7 @@
* @param indexingQueue the indexing queue.
* @throws IOException if the index cannot be initialized.
*/
- AbstractIndex(Analyzer analyzer, Similarity similarity, Directory directory,
DocNumberCache cache,
+ AbstractIndex(final Analyzer analyzer, Similarity similarity, final Directory
directory, DocNumberCache cache,
IndexingQueue indexingQueue) throws IOException
{
this.analyzer = analyzer;
@@ -130,15 +133,24 @@
this.directory = directory;
this.cache = cache;
this.indexingQueue = indexingQueue;
- this.isExisting = IndexReader.indexExists(directory);
- if (!isExisting)
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- indexWriter = new IndexWriter(directory, analyzer,
IndexWriter.MaxFieldLength.LIMITED);
- // immediately close, now that index has been created
- indexWriter.close();
- indexWriter = null;
- }
+ public Object run() throws Exception
+ {
+ AbstractIndex.this.isExisting = IndexReader.indexExists(directory);
+
+ if (!isExisting)
+ {
+ indexWriter = new IndexWriter(directory, analyzer,
IndexWriter.MaxFieldLength.LIMITED);
+ // immediately close, now that index has been created
+ indexWriter.close();
+ indexWriter = null;
+ }
+ return null;
+ }
+ });
+
}
/**
@@ -170,60 +182,67 @@
* @param docs the documents to add.
* @throws IOException if an error occurs while writing to the index.
*/
- void addDocuments(Document[] docs) throws IOException
+ void addDocuments(final Document[] docs) throws IOException
{
- final IndexWriter writer = getIndexWriter();
- DynamicPooledExecutor.Command[] commands = new
DynamicPooledExecutor.Command[docs.length];
- for (int i = 0; i < docs.length; i++)
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- // check if text extractor completed its work
- final Document doc = getFinishedDocument(docs[i]);
- // create a command for inverting the document
- commands[i] = new DynamicPooledExecutor.Command()
+ public Object run() throws Exception
{
- public Object call() throws Exception
+ final IndexWriter writer = getIndexWriter();
+ DynamicPooledExecutor.Command[] commands = new
DynamicPooledExecutor.Command[docs.length];
+ for (int i = 0; i < docs.length; i++)
{
- long time = System.currentTimeMillis();
- writer.addDocument(doc);
- return new Long(System.currentTimeMillis() - time);
+ // check if text extractor completed its work
+ final Document doc = getFinishedDocument(docs[i]);
+ // create a command for inverting the document
+ commands[i] = new DynamicPooledExecutor.Command()
+ {
+ public Object call() throws Exception
+ {
+ long time = System.currentTimeMillis();
+ writer.addDocument(doc);
+ return new Long(System.currentTimeMillis() - time);
+ }
+ };
}
- };
- }
- DynamicPooledExecutor.Result[] results = EXECUTOR.executeAndWait(commands);
- invalidateSharedReader();
- IOException ex = null;
- for (int i = 0; i < results.length; i++)
- {
- if (results[i].getException() != null)
- {
- Throwable cause = results[i].getException().getCause();
- if (ex == null)
+ DynamicPooledExecutor.Result[] results = EXECUTOR.executeAndWait(commands);
+ invalidateSharedReader();
+ IOException ex = null;
+ for (int i = 0; i < results.length; i++)
{
- // only throw the first exception
- if (cause instanceof IOException)
+ if (results[i].getException() != null)
{
- ex = (IOException)cause;
+ Throwable cause = results[i].getException().getCause();
+ if (ex == null)
+ {
+ // only throw the first exception
+ if (cause instanceof IOException)
+ {
+ ex = (IOException)cause;
+ }
+ else
+ {
+ throw Util.createIOException(cause);
+ }
+ }
+ else
+ {
+ // all others are logged
+ log.warn("Exception while inverting document", cause);
+ }
}
else
{
- throw Util.createIOException(cause);
+ log.debug("Inverted document in {} ms", results[i].get());
}
}
- else
+ if (ex != null)
{
- // all others are logged
- log.warn("Exception while inverting document", cause);
+ throw ex;
}
+ return null;
}
- else
- {
- log.debug("Inverted document in {} ms", results[i].get());
- }
- }
- if (ex != null)
- {
- throw ex;
- }
+ });
}
/**
@@ -235,9 +254,15 @@
* @throws IOException if an error occurs while removing the document.
* @return number of documents deleted
*/
- int removeDocument(Term idTerm) throws IOException
+ int removeDocument(final Term idTerm) throws IOException
{
- return getIndexReader().deleteDocuments(idTerm);
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return getIndexReader().deleteDocuments(idTerm);
+ }
+ });
}
/**
@@ -249,20 +274,26 @@
*/
protected synchronized CommittableIndexReader getIndexReader() throws IOException
{
- if (indexWriter != null)
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<CommittableIndexReader>()
{
- indexWriter.close();
- log.debug("closing IndexWriter.");
- indexWriter = null;
- }
+ public CommittableIndexReader run() throws Exception
+ {
+ if (indexWriter != null)
+ {
+ indexWriter.close();
+ log.debug("closing IndexWriter.");
+ indexWriter = null;
+ }
- if (indexReader == null || !indexReader.isCurrent())
- {
- IndexReader reader = IndexReader.open(getDirectory());
- reader.setTermInfosIndexDivisor(termInfosIndexDivisor);
- indexReader = new CommittableIndexReader(reader);
- }
- return indexReader;
+ if (indexReader == null || !indexReader.isCurrent())
+ {
+ IndexReader reader = IndexReader.open(getDirectory());
+ reader.setTermInfosIndexDivisor(termInfosIndexDivisor);
+ indexReader = new CommittableIndexReader(reader);
+ }
+ return indexReader;
+ }
+ });
}
/**
@@ -276,60 +307,66 @@
* @return a read-only index reader.
* @throws IOException if an error occurs while obtaining the index reader.
*/
- synchronized ReadOnlyIndexReader getReadOnlyIndexReader(boolean initCache) throws
IOException
+ synchronized ReadOnlyIndexReader getReadOnlyIndexReader(final boolean initCache)
throws IOException
{
- // get current modifiable index reader
- CommittableIndexReader modifiableReader = getIndexReader();
- long modCount = modifiableReader.getModificationCount();
- if (readOnlyReader != null)
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<ReadOnlyIndexReader>()
{
- if (readOnlyReader.getDeletedDocsVersion() == modCount)
+ public ReadOnlyIndexReader run() throws Exception
{
- // reader up-to-date
- readOnlyReader.acquire();
- return readOnlyReader;
- }
- else
- {
- // reader outdated
- if (readOnlyReader.getRefCount() == 1)
+ // get current modifiable index reader
+ CommittableIndexReader modifiableReader = getIndexReader();
+ long modCount = modifiableReader.getModificationCount();
+ if (readOnlyReader != null)
{
- // not in use, except by this index
- // update the reader
- readOnlyReader.updateDeletedDocs(modifiableReader);
- readOnlyReader.acquire();
- return readOnlyReader;
+ if (readOnlyReader.getDeletedDocsVersion() == modCount)
+ {
+ // reader up-to-date
+ readOnlyReader.acquire();
+ return readOnlyReader;
+ }
+ else
+ {
+ // reader outdated
+ if (readOnlyReader.getRefCount() == 1)
+ {
+ // not in use, except by this index
+ // update the reader
+ readOnlyReader.updateDeletedDocs(modifiableReader);
+ readOnlyReader.acquire();
+ return readOnlyReader;
+ }
+ else
+ {
+ // cannot update reader, it is still in use
+ // need to create a new instance
+ readOnlyReader.release();
+ readOnlyReader = null;
+ }
+ }
}
- else
+ // if we get here there is no up-to-date read-only reader
+ // capture snapshot of deleted documents
+ BitSet deleted = new BitSet(modifiableReader.maxDoc());
+ for (int i = 0; i < modifiableReader.maxDoc(); i++)
{
- // cannot update reader, it is still in use
- // need to create a new instance
- readOnlyReader.release();
- readOnlyReader = null;
+ if (modifiableReader.isDeleted(i))
+ {
+ deleted.set(i);
+ }
}
+ if (sharedReader == null)
+ {
+ // create new shared reader
+ IndexReader reader = IndexReader.open(getDirectory(), true);
+ reader.setTermInfosIndexDivisor(termInfosIndexDivisor);
+ CachingIndexReader cr = new CachingIndexReader(reader, cache, initCache);
+ sharedReader = new SharedIndexReader(cr);
+ }
+ readOnlyReader = new ReadOnlyIndexReader(sharedReader, deleted, modCount);
+ readOnlyReader.acquire();
+ return readOnlyReader;
}
- }
- // if we get here there is no up-to-date read-only reader
- // capture snapshot of deleted documents
- BitSet deleted = new BitSet(modifiableReader.maxDoc());
- for (int i = 0; i < modifiableReader.maxDoc(); i++)
- {
- if (modifiableReader.isDeleted(i))
- {
- deleted.set(i);
- }
- }
- if (sharedReader == null)
- {
- // create new shared reader
- IndexReader reader = IndexReader.open(getDirectory(), true);
- reader.setTermInfosIndexDivisor(termInfosIndexDivisor);
- CachingIndexReader cr = new CachingIndexReader(reader, cache, initCache);
- sharedReader = new SharedIndexReader(cr);
- }
- readOnlyReader = new ReadOnlyIndexReader(sharedReader, deleted, modCount);
- readOnlyReader.acquire();
- return readOnlyReader;
+ });
}
/**
@@ -353,20 +390,26 @@
*/
protected synchronized IndexWriter getIndexWriter() throws IOException
{
- if (indexReader != null)
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<IndexWriter>()
{
- indexReader.close();
- log.debug("closing IndexReader.");
- indexReader = null;
- }
- if (indexWriter == null)
- {
- indexWriter = new IndexWriter(getDirectory(), analyzer, new
IndexWriter.MaxFieldLength(maxFieldLength));
- indexWriter.setSimilarity(similarity);
- indexWriter.setUseCompoundFile(useCompoundFile);
- indexWriter.setInfoStream(STREAM_LOGGER);
- }
- return indexWriter;
+ public IndexWriter run() throws Exception
+ {
+ if (indexReader != null)
+ {
+ indexReader.close();
+ log.debug("closing IndexReader.");
+ indexReader = null;
+ }
+ if (indexWriter == null)
+ {
+ indexWriter = new IndexWriter(getDirectory(), analyzer, new
IndexWriter.MaxFieldLength(maxFieldLength));
+ indexWriter.setSimilarity(similarity);
+ indexWriter.setUseCompoundFile(useCompoundFile);
+ indexWriter.setInfoStream(STREAM_LOGGER);
+ }
+ return indexWriter;
+ }
+ });
}
/**
@@ -385,26 +428,33 @@
* commit.
* @throws IOException if an error occurs while commiting changes.
*/
- protected synchronized void commit(boolean optimize) throws IOException
+ protected synchronized void commit(final boolean optimize) throws IOException
{
- if (indexReader != null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- log.debug("committing IndexReader.");
- indexReader.flush();
- }
- if (indexWriter != null)
- {
- log.debug("committing IndexWriter.");
- indexWriter.commit();
- }
- // optimize if requested
- if (optimize)
- {
- IndexWriter writer = getIndexWriter();
- writer.optimize();
- writer.close();
- indexWriter = null;
- }
+ public Object run() throws Exception
+ {
+ if (indexReader != null)
+ {
+ log.debug("committing IndexReader.");
+ indexReader.flush();
+ }
+ if (indexWriter != null)
+ {
+ log.debug("committing IndexWriter.");
+ indexWriter.commit();
+ }
+ // optimize if requested
+ if (optimize)
+ {
+ IndexWriter writer = getIndexWriter();
+ writer.optimize();
+ writer.close();
+ indexWriter = null;
+ }
+ return null;
+ }
+ });
}
/**
@@ -412,18 +462,25 @@
*/
synchronized void close()
{
- releaseWriterAndReaders();
- if (directory != null)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- try
+ public Object run()
{
- directory.close();
+ releaseWriterAndReaders();
+ if (directory != null)
+ {
+ try
+ {
+ directory.close();
+ }
+ catch (IOException e)
+ {
+ directory = null;
+ }
+ }
+ return null;
}
- catch (IOException e)
- {
- directory = null;
- }
- }
+ });
}
/**
@@ -431,54 +488,61 @@
*/
protected void releaseWriterAndReaders()
{
- if (indexWriter != null)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- try
+ public Object run()
{
- indexWriter.close();
+ if (indexWriter != null)
+ {
+ try
+ {
+ indexWriter.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception closing index writer: " + e.toString());
+ }
+ indexWriter = null;
+ }
+ if (indexReader != null)
+ {
+ try
+ {
+ indexReader.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception closing index reader: " + e.toString());
+ }
+ indexReader = null;
+ }
+ if (readOnlyReader != null)
+ {
+ try
+ {
+ readOnlyReader.release();
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception closing index reader: " + e.toString());
+ }
+ readOnlyReader = null;
+ }
+ if (sharedReader != null)
+ {
+ try
+ {
+ sharedReader.release();
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception closing index reader: " + e.toString());
+ }
+ sharedReader = null;
+ }
+ return null;
}
- catch (IOException e)
- {
- log.warn("Exception closing index writer: " + e.toString());
- }
- indexWriter = null;
- }
- if (indexReader != null)
- {
- try
- {
- indexReader.close();
- }
- catch (IOException e)
- {
- log.warn("Exception closing index reader: " + e.toString());
- }
- indexReader = null;
- }
- if (readOnlyReader != null)
- {
- try
- {
- readOnlyReader.release();
- }
- catch (IOException e)
- {
- log.warn("Exception closing index reader: " + e.toString());
- }
- readOnlyReader = null;
- }
- if (sharedReader != null)
- {
- try
- {
- sharedReader.release();
- }
- catch (IOException e)
- {
- log.warn("Exception closing index reader: " + e.toString());
- }
- sharedReader = null;
- }
+ });
}
/**
@@ -503,18 +567,25 @@
*/
protected synchronized void invalidateSharedReader() throws IOException
{
- // also close the read-only reader
- if (readOnlyReader != null)
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- readOnlyReader.release();
- readOnlyReader = null;
- }
- // invalidate shared reader
- if (sharedReader != null)
- {
- sharedReader.release();
- sharedReader = null;
- }
+ public Object run() throws Exception
+ {
+ // also close the read-only reader
+ if (readOnlyReader != null)
+ {
+ readOnlyReader.release();
+ readOnlyReader = null;
+ }
+ // invalidate shared reader
+ if (sharedReader != null)
+ {
+ sharedReader.release();
+ sharedReader = null;
+ }
+ return null;
+ }
+ });
}
/**
@@ -708,6 +779,7 @@
{
super(new OutputStream()
{
+ @Override
public void write(int b)
{
// do nothing
@@ -715,11 +787,13 @@
});
}
+ @Override
public void print(String s)
{
buffer.append(s);
}
+ @Override
public void println(String s)
{
buffer.append(s);
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -19,12 +19,14 @@
import org.apache.lucene.store.Directory;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexOutputStream;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -112,28 +114,35 @@
*/
public void read() throws IOException
{
- names.clear();
- indexes.clear();
- if (dir.fileExists(name))
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- // clear current lists
- InputStream in = new IndexInputStream(dir.openInput(name));
- try
+ public Object run() throws Exception
{
- DataInputStream di = new DataInputStream(in);
- counter = di.readInt();
- for (int i = di.readInt(); i > 0; i--)
+ names.clear();
+ indexes.clear();
+ if (dir.fileExists(name))
{
- String indexName = di.readUTF();
- indexes.add(indexName);
- names.add(indexName);
+ // clear current lists
+ InputStream in = new IndexInputStream(dir.openInput(name));
+ try
+ {
+ DataInputStream di = new DataInputStream(in);
+ counter = di.readInt();
+ for (int i = di.readInt(); i > 0; i--)
+ {
+ String indexName = di.readUTF();
+ indexes.add(indexName);
+ names.add(indexName);
+ }
+ }
+ finally
+ {
+ in.close();
+ }
}
+ return null;
}
- finally
- {
- in.close();
- }
- }
+ });
}
/**
@@ -144,34 +153,41 @@
*/
public void write() throws IOException
{
- // do not write if not dirty
- if (!dirty)
+ SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Object>()
{
- return;
- }
+ public Object run() throws Exception
+ {
+ // do not write if not dirty
+ if (!dirty)
+ {
+ return null;
+ }
- OutputStream out = new IndexOutputStream(dir.createOutput(name +
".new"));
- try
- {
- DataOutputStream dataOut = new DataOutputStream(out);
- dataOut.writeInt(counter);
- dataOut.writeInt(indexes.size());
- for (int i = 0; i < indexes.size(); i++)
- {
- dataOut.writeUTF(getName(i));
+ OutputStream out = new IndexOutputStream(dir.createOutput(name +
".new"));
+ try
+ {
+ DataOutputStream dataOut = new DataOutputStream(out);
+ dataOut.writeInt(counter);
+ dataOut.writeInt(indexes.size());
+ for (int i = 0; i < indexes.size(); i++)
+ {
+ dataOut.writeUTF(getName(i));
+ }
+ }
+ finally
+ {
+ out.close();
+ }
+ // delete old
+ if (dir.fileExists(name))
+ {
+ dir.deleteFile(name);
+ }
+ dir.renameFile(name + ".new", name);
+ dirty = false;
+ return null;
}
- }
- finally
- {
- out.close();
- }
- // delete old
- if (dir.fileExists(name))
- {
- dir.deleteFile(name);
- }
- dir.renameFile(name + ".new", name);
- dirty = false;
+ });
}
/**
@@ -181,7 +197,7 @@
*/
public String getName(int i)
{
- return (String)indexes.get(i);
+ return indexes.get(i);
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -20,6 +20,8 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.NativeFSLockFactory;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
@@ -29,11 +31,14 @@
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener;
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.DirectoryManager;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -824,60 +829,67 @@
* @throws IOException
* if an error occurs constructing the
<code>IndexReader</code>.
*/
- public synchronized CachingMultiIndexReader getIndexReader(boolean initCache) throws
IOException
+ public synchronized CachingMultiIndexReader getIndexReader(final boolean initCache)
throws IOException
{
- synchronized (updateMonitor)
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<CachingMultiIndexReader>()
{
- if (multiReader != null)
+ public CachingMultiIndexReader run() throws Exception
{
- multiReader.acquire();
- return multiReader;
- }
- // no reader available
- // wait until no update is in progress
- while (indexUpdateMonitor.getUpdateInProgress())
- {
- try
+ synchronized (updateMonitor)
{
- updateMonitor.wait();
- }
- catch (InterruptedException e)
- {
- throw new IOException("Interrupted while waiting to aquire
reader");
- }
- }
- // some other read thread might have created the reader in the
- // meantime -> check again
- if (multiReader == null)
- {
- List readerList = new ArrayList();
- for (int i = 0; i < indexes.size(); i++)
- {
- PersistentIndex pIdx = (PersistentIndex)indexes.get(i);
-
- if (indexNames.contains(pIdx.getName()))
+ if (multiReader != null)
{
+ multiReader.acquire();
+ return multiReader;
+ }
+ // no reader available
+ // wait until no update is in progress
+ while (indexUpdateMonitor.getUpdateInProgress())
+ {
try
{
- readerList.add(pIdx.getReadOnlyIndexReader(initCache));
+ updateMonitor.wait();
}
- catch (FileNotFoundException e)
+ catch (InterruptedException e)
{
- if (directoryManager.hasDirectory(pIdx.getName()))
+ throw new IOException("Interrupted while waiting to aquire
reader");
+ }
+ }
+ // some other read thread might have created the reader in the
+ // meantime -> check again
+ if (multiReader == null)
+ {
+ List readerList = new ArrayList();
+ for (int i = 0; i < indexes.size(); i++)
+ {
+ PersistentIndex pIdx = (PersistentIndex)indexes.get(i);
+
+ if (indexNames.contains(pIdx.getName()))
{
- throw e;
+ try
+ {
+ readerList.add(pIdx.getReadOnlyIndexReader(initCache));
+ }
+ catch (FileNotFoundException e)
+ {
+ if (directoryManager.hasDirectory(pIdx.getName()))
+ {
+ throw e;
+ }
+ }
}
}
+ readerList.add(volatileIndex.getReadOnlyIndexReader());
+ ReadOnlyIndexReader[] readers =
+ (ReadOnlyIndexReader[])readerList.toArray(new
ReadOnlyIndexReader[readerList.size()]);
+ multiReader = new CachingMultiIndexReader(readers, cache);
}
+ multiReader.acquire();
+ return multiReader;
}
- readerList.add(volatileIndex.getReadOnlyIndexReader());
- ReadOnlyIndexReader[] readers =
- (ReadOnlyIndexReader[])readerList.toArray(new
ReadOnlyIndexReader[readerList.size()]);
- multiReader = new CachingMultiIndexReader(readers, cache);
}
- multiReader.acquire();
- return multiReader;
- }
+ });
+
}
/**
@@ -1159,6 +1171,7 @@
// new flush task, cause canceled can't be re-used
flushTask = new TimerTask()
{
+ @Override
public void run()
{
// check if there are any indexing jobs finished
@@ -1204,19 +1217,25 @@
* if an error occurs while executing the action or appending
* the action to the redo log.
*/
- private Action executeAndLog(Action a) throws IOException
+ private Action executeAndLog(final Action a) throws IOException
{
- a.execute(this);
- redoLog.append(a);
- // please note that flushing the redo log is only required on
- // commit, but we also want to keep track of new indexes for sure.
- // otherwise it might happen that unused index folders are orphaned
- // after a crash.
- if (a.getType() == Action.TYPE_COMMIT || a.getType() == Action.TYPE_ADD_INDEX)
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<Action>()
{
- redoLog.flush();
- }
- return a;
+ public Action run() throws Exception
+ {
+ a.execute(MultiIndex.this);
+ redoLog.append(a);
+ // please note that flushing the redo log is only required on
+ // commit, but we also want to keep track of new indexes for sure.
+ // otherwise it might happen that unused index folders are orphaned
+ // after a crash.
+ if (a.getType() == Action.TYPE_COMMIT || a.getType() ==
Action.TYPE_ADD_INDEX)
+ {
+ redoLog.flush();
+ }
+ return a;
+ }
+ });
}
/**
@@ -1670,6 +1689,7 @@
*
* @return a <code>String</code> representation of this action.
*/
+ @Override
public abstract String toString();
/**
@@ -1797,6 +1817,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
PersistentIndex idx = index.getOrCreateIndex(indexName);
@@ -1812,6 +1833,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer();
@@ -1901,6 +1923,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
if (doc == null)
@@ -1924,6 +1947,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
@@ -1972,6 +1996,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
index.lastFlushTime = System.currentTimeMillis();
@@ -1980,6 +2005,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
return Long.toString(getTransactionId()) + ' ' + Action.COMMIT;
@@ -2035,6 +2061,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
PersistentIndex idx = index.getOrCreateIndex(indexName);
@@ -2044,6 +2071,7 @@
/**
* @inheritDoc
*/
+ @Override
public void undo(MultiIndex index) throws IOException
{
if (index.hasIndex(indexName))
@@ -2057,6 +2085,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer();
@@ -2127,6 +2156,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
// get index if it exists
@@ -2145,6 +2175,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer();
@@ -2214,6 +2245,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
String uuidString = uuid.toString();
@@ -2249,6 +2281,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
@@ -2297,6 +2330,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
index.currentTransactionId = getTransactionId();
@@ -2305,6 +2339,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
return Long.toString(getTransactionId()) + ' ' + Action.START;
@@ -2353,6 +2388,7 @@
*
* @inheritDoc
*/
+ @Override
public void execute(MultiIndex index) throws IOException
{
VolatileIndex volatileIndex = index.getVolatileIndex();
@@ -2364,6 +2400,7 @@
/**
* @inheritDoc
*/
+ @Override
public String toString()
{
StringBuffer logLine = new StringBuffer();
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
/**
@@ -49,7 +50,7 @@
{
public Object run() throws Exception
{
- baseDir = PrivilegedFileHelper.file(handler.getPath());
+ baseDir = new File(handler.getPath());
return null;
}
});
@@ -64,7 +65,7 @@
{
public Boolean run() throws Exception
{
- return PrivilegedFileHelper.file(baseDir, name).exists();
+ return new File(baseDir, name).exists();
}
});
@@ -86,7 +87,7 @@
}
else
{
- dir = PrivilegedFileHelper.file(baseDir, name);
+ dir = new File(baseDir, name);
}
return FSDirectory.getDirectory(dir, new NativeFSLockFactory(dir));
}
@@ -131,11 +132,11 @@
*/
public boolean delete(final String name)
{
- return SecurityHelper.doPriviledgedAction(new
PrivilegedExceptionAction<Boolean>()
+ return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Boolean>()
{
- public Boolean run() throws Exception
+ public Boolean run()
{
- File directory = PrivilegedFileHelper.file(baseDir, name);
+ File directory = new File(baseDir, name);
// trivial if it does not exist anymore
if (!directory.exists())
{
@@ -168,12 +169,12 @@
*/
public boolean rename(final String from, final String to)
{
- return SecurityHelper.doPriviledgedAction(new
PrivilegedExceptionAction<Boolean>()
+ return SecurityHelper.doPriviledgedAction(new PrivilegedAction<Boolean>()
{
- public Boolean run() throws Exception
+ public Boolean run()
{
- File src = PrivilegedFileHelper.file(baseDir, from);
- File dest = PrivilegedFileHelper.file(baseDir, to);
+ File src = new File(baseDir, from);
+ File dest = new File(baseDir, to);
return src.renameTo(dest);
}
});
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -18,8 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.util;
+import java.io.File;
import java.io.IOException;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -73,24 +75,26 @@
* @return
* @throws IOException
*/
- public static <E> E doPriviledgedAction(PrivilegedExceptionAction<E>
action)
+ public static <E> E doPriviledgedAction(PrivilegedAction<E> action)
{
- try
+ return AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Gets system property in privileged mode
+ *
+ * @param name
+ * @return
+ */
+ public static String getSystemProperty(final String name)
+ {
+ return SecurityHelper.doPriviledgedAction(new PrivilegedAction<String>()
{
- return AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = pae.getCause();
- if (cause instanceof RuntimeException)
+ public String run()
{
- throw (RuntimeException)cause;
+ return System.getProperty(name);
}
- else
- {
- throw new RuntimeException(cause);
- }
- }
+ });
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/IndexingQueueTest.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/IndexingQueueTest.java 2010-06-14
08:17:58 UTC (rev 2564)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/IndexingQueueTest.java 2010-06-14
08:44:23 UTC (rev 2565)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexingQueue;
import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import javax.jcr.Node;
@@ -44,7 +45,7 @@
public class IndexingQueueTest extends AbstractIndexingTest
{
- private static final File TEMP_DIR =
PrivilegedFileHelper.file(System.getProperty("java.io.tmpdir"));
+ private static final File TEMP_DIR = new
File(SecurityHelper.getSystemProperty("java.io.tmpdir"));
private static final String CONTENT_TYPE =
"application/indexing-queue-test";