org.compass.core.lucene.engine.transaction.support
Class AbstractConcurrentTransactionProcessor

java.lang.Object
  extended by org.compass.core.lucene.engine.transaction.support.AbstractTransactionProcessor
      extended by org.compass.core.lucene.engine.transaction.support.AbstractSearchTransactionProcessor
          extended by org.compass.core.lucene.engine.transaction.support.AbstractConcurrentTransactionProcessor
All Implemented Interfaces:
TransactionProcessor
Direct Known Subclasses:
LuceneTransactionProcessor, ReadCommittedTransactionProcessor

public abstract class AbstractConcurrentTransactionProcessor
extends AbstractSearchTransactionProcessor

Base class support for async dirty operation processing.

Each dirty operation is added to a backlog for a specific thread to proces it (obtained from ExecutorManager). A AbstractConcurrentTransactionProcessor.Processor is assigned for each thread responsible for processing dirty operations.

Extedning classes should implement teh required operations and provide indication as to if search/read operations should block until all dirty operations have been processed, and if concurrent operations are even allowed. In case concurrent operations are not allowed, all dirty operations will be perfomed in a sync manner.

Different settings can control how the concurrent processing is perfomed. Settings names are based on TransactionProcessor.getName() by using AbstractTransactionProcessor.getSettingName(String).

The concurrentOperations setting can be used to disable concurrent dirty operations, or enable them. This is only applies of the concurrentOperations parameter in the constructor is true.

The number of processor threads can be controlled using concurrencyLevel setting. It defaults to 5 threads.

Operations are hashed to their respective processor thread for procesing. Hashing can be controlled to either be perofmed based on uid or subindex. The default is uid.

The size of the backlog for each processor thread can also be controlled. If the backlog is full, user operations will block until space becaomes available (by the respective processor processing the operations). The amount of time the operation will block can be controlled using the addTimeout setting which defaults to 10 seconds.

Author:
kimchy

Field Summary
 
Fields inherited from class org.compass.core.lucene.engine.transaction.support.AbstractTransactionProcessor
indexManager, logger, mapping, searchEngine, searchEngineFactory
 
Constructor Summary
protected AbstractConcurrentTransactionProcessor(org.apache.commons.logging.Log logger, LuceneSearchEngine searchEngine, boolean waitForSearchOperations, boolean concurrentOperations)
           
 
Method Summary
 void begin()
          Begin the transaction.
 void commit(boolean onePhase)
          Commit the trnasction.
 void create(InternalResource resource)
          Creates a resource.
 void delete(LuceneSearchEngineQuery query)
          Delets everything that match the given query.
 void delete(ResourceKey resourceKey)
          Deletes a resource based on the resource key.
protected abstract  void doCommit(boolean onePhase)
          Sub classes should implement this.
protected abstract  LuceneSearchEngineHits doFind(LuceneSearchEngineQuery query)
          Sub classes should implement this.
protected  void doFlush()
           
protected abstract  Resource[] doGet(ResourceKey resourceKey)
          Base classes should implement this.
protected abstract  LuceneSearchEngineInternalSearch doInternalSearch(String[] subIndexes, String[] aliases)
          Base classes should implement this.
protected abstract  void doPrepare()
          Sub classes should implement this.
protected abstract  void doProcessJob(TransactionJob job)
          Sub classes should implement the actual processing of a transactional job.
protected abstract  void doRollback()
          Sub classes should implement this.
 LuceneSearchEngineHits find(LuceneSearchEngineQuery query)
          Perform a search for the given query and returns the hits for it.
 void flush()
          Flush changes.
 void flushCommit(String... aliases)
          Flush changes and make them visible for other transactions.
 Resource[] get(ResourceKey resourceKey)
          Returns the resources tha match a resource key.
protected abstract  String[] getDirtySubIndexes()
          Returns the current dirty sub indexes.
 LuceneSearchEngineInternalSearch internalSearch(String[] subIndexes, String[] aliases)
          Performs an internal search operation.
 boolean isConcurrentOperations()
          Returns true if concurrent operaetions are enabled for this transaction processor.
 void prepare()
          Prepare the transaction for commit.
protected abstract  void prepareBeforeAsyncDirtyOperation(TransactionJob job)
          Called by a single thread (the calling thread) before a dirty transaction job is added to the queue to be executed in an async manner.
 void rollback()
          Rollback the transaction.
 void update(InternalResource resource)
          Updates a resource.
 
Methods inherited from class org.compass.core.lucene.engine.transaction.support.AbstractSearchTransactionProcessor
performFind, performGet, performInternalSearch
 
Methods inherited from class org.compass.core.lucene.engine.transaction.support.AbstractTransactionProcessor
buildInternalSearch, findByQuery, getResourceMapping, getSettingName, isInvalidateCacheOnCommit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.compass.core.lucene.engine.transaction.TransactionProcessor
getName
 

Constructor Detail

AbstractConcurrentTransactionProcessor

protected AbstractConcurrentTransactionProcessor(org.apache.commons.logging.Log logger,
                                                 LuceneSearchEngine searchEngine,
                                                 boolean waitForSearchOperations,
                                                 boolean concurrentOperations)
Method Detail

isConcurrentOperations

public boolean isConcurrentOperations()
Returns true if concurrent operaetions are enabled for this transaction processor.


begin

public void begin()
           throws SearchEngineException
Description copied from interface: TransactionProcessor
Begin the transaction.

Throws:
SearchEngineException

prepare

public void prepare()
             throws SearchEngineException
Description copied from interface: TransactionProcessor
Prepare the transaction for commit.

Throws:
SearchEngineException

doPrepare

protected abstract void doPrepare()
                           throws SearchEngineException
Sub classes should implement this. Behaviour should be the same as prepare().

Throws:
SearchEngineException

commit

public void commit(boolean onePhase)
            throws SearchEngineException
Description copied from interface: TransactionProcessor
Commit the trnasction. If onePhase is set to true then should perform both the prepare phase and the commit phase. If it is set to false then just needs to perform the second phase of the commit process.

Throws:
SearchEngineException

doCommit

protected abstract void doCommit(boolean onePhase)
                          throws SearchEngineException
Sub classes should implement this. Behaviour should be the same as commit(boolean).

Throws:
SearchEngineException

rollback

public void rollback()
              throws SearchEngineException
Description copied from interface: TransactionProcessor
Rollback the transaction.

Throws:
SearchEngineException

doRollback

protected abstract void doRollback()
                            throws SearchEngineException
Sub classes should implement this. Behaviour should be the same as rollback().

Throws:
SearchEngineException

flush

public void flush()
           throws SearchEngineException
Description copied from interface: TransactionProcessor
Flush changes. Note, the implementation needs to strive for changes not to be visible to other transactions.

Throws:
SearchEngineException

doFlush

protected void doFlush()
                throws SearchEngineException
Throws:
SearchEngineException

create

public void create(InternalResource resource)
            throws SearchEngineException
Description copied from interface: TransactionProcessor
Creates a resource.

Throws:
SearchEngineException

update

public void update(InternalResource resource)
            throws SearchEngineException
Description copied from interface: TransactionProcessor
Updates a resource.

Throws:
SearchEngineException

delete

public void delete(ResourceKey resourceKey)
            throws SearchEngineException
Description copied from interface: TransactionProcessor
Deletes a resource based on the resource key.

Throws:
SearchEngineException

delete

public void delete(LuceneSearchEngineQuery query)
            throws SearchEngineException
Description copied from interface: TransactionProcessor
Delets everything that match the given query.

Throws:
SearchEngineException

flushCommit

public void flushCommit(String... aliases)
                 throws SearchEngineException
Description copied from interface: TransactionProcessor
Flush changes and make them visible for other transactions. Note, operations performed up until the flush commit was called might not be able to roll back.

Throws:
SearchEngineException

getDirtySubIndexes

protected abstract String[] getDirtySubIndexes()
Returns the current dirty sub indexes.


doProcessJob

protected abstract void doProcessJob(TransactionJob job)
                              throws SearchEngineException
Sub classes should implement the actual processing of a transactional job.

Throws:
SearchEngineException

prepareBeforeAsyncDirtyOperation

protected abstract void prepareBeforeAsyncDirtyOperation(TransactionJob job)
                                                  throws SearchEngineException
Called by a single thread (the calling thread) before a dirty transaction job is added to the queue to be executed in an async manner.

Throws:
SearchEngineException

find

public LuceneSearchEngineHits find(LuceneSearchEngineQuery query)
                            throws SearchEngineException
Description copied from interface: TransactionProcessor
Perform a search for the given query and returns the hits for it.

Throws:
SearchEngineException

doFind

protected abstract LuceneSearchEngineHits doFind(LuceneSearchEngineQuery query)
                                          throws SearchEngineException
Sub classes should implement this. Behaviour should be the same as find(org.compass.core.lucene.engine.LuceneSearchEngineQuery).

Throws:
SearchEngineException

internalSearch

public LuceneSearchEngineInternalSearch internalSearch(String[] subIndexes,
                                                       String[] aliases)
                                                throws SearchEngineException
Description copied from interface: TransactionProcessor
Performs an internal search operation.

Throws:
SearchEngineException

doInternalSearch

protected abstract LuceneSearchEngineInternalSearch doInternalSearch(String[] subIndexes,
                                                                     String[] aliases)
                                                              throws SearchEngineException
Base classes should implement this. Behaviour should be the same as internalSearch(String[], String[]).

Throws:
SearchEngineException

get

public Resource[] get(ResourceKey resourceKey)
               throws SearchEngineException
Description copied from interface: TransactionProcessor
Returns the resources tha match a resource key.

Note, should usually only return one resource.

Throws:
SearchEngineException

doGet

protected abstract Resource[] doGet(ResourceKey resourceKey)
                             throws SearchEngineException
Base classes should implement this. Behaviour should be the same as get(org.compass.core.spi.ResourceKey).

Throws:
SearchEngineException


Copyright (c) 2004-2009 The Compass Project.