Package org.eclipse.rdf4j.sail.memory
Class MemorySailStore
- java.lang.Object
-
- org.eclipse.rdf4j.sail.memory.MemorySailStore
-
- All Implemented Interfaces:
java.lang.AutoCloseable,SailClosable,SailStore
class MemorySailStore extends java.lang.Object implements SailStore
An implementation ofSailStorethat keeps committed statements in aMemStatementList.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMemorySailStore.MemorySailDatasetprivate classMemorySailStore.MemorySailSinkprivate classMemorySailStore.MemorySailSource(package private) static classMemorySailStore.SnapshotMonitorSnapshotMonitor is used to keep track of which snapshot version are no longer is use (read or write) so that we can safely clean that snapshot version.
-
Field Summary
Fields Modifier and Type Field Description private static intCLEANUP_MAX_MEMORY_THRESHOLDprivate static intCLEANUP_MINIMUM_FREE_MEMORYprivate static doubleCLEANUP_MINIMUM_FREE_MEMORY_RATIOprivate intcurrentSnapshotIdentifies the current snapshot.static MemResource[]EMPTY_CONTEXTstatic EmptyIteration<MemStatement,SailException>EMPTY_ITERATIONstatic EmptyIteration<MemTriple,SailException>EMPTY_TRIPLE_ITERATIONprivate MemStatementIteratorCacheiteratorCacheprivate static org.slf4j.Loggerloggerprivate static longMAX_MEMORYprivate booleanmayHaveInferredThis gets set to `true` when we add our first inferred statement.private MemNamespaceStorenamespaceStoreStore for namespace prefix info.static MemResource[]NULL_CONTEXTprivate static java.lang.RuntimeRUNTIMEprivate java.lang.ThreadsnapshotCleanupThreadCleanup thread that removes deprecated statements when no other threads are accessing this list.private java.lang.ObjectsnapshotCleanupThreadLockObjectLock object used to synchronize concurrent access tosnapshotCleanupThread.(package private) MemorySailStore.SnapshotMonitorsnapshotMonitorprivate MemStatementListstatementsList containing all available statements.private java.util.concurrent.locks.ReentrantLocktxnLockManagerLock manager used to prevent concurrent writes.private MemValueFactoryvalueFactoryFactory/cache for MemValue objects.
-
Constructor Summary
Constructors Constructor Description MemorySailStore(boolean debug)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanSnapshots()Removes statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.voidclose()Closes this resource, relinquishing any underlying resources.private SailExceptionconvertToSailException(java.lang.InterruptedException e)private CloseableIteration<MemStatement,SailException>createStatementIterator(Resource subj, IRI pred, Value obj, java.lang.Boolean explicit, int snapshot, Resource... contexts)Creates a StatementIterator that contains the statements matching the specified pattern of subject, predicate, object, context.private CloseableIteration<MemTriple,SailException>createTripleIterator(Resource subj, IRI pred, Value obj, int snapshot)Creates a TripleIterator that contains the triples matching the specified pattern of subject, predicate, object, context.EvaluationStatisticsgetEvaluationStatistics()Used bySailSourceConnectionto determine query join order.SailSourcegetExplicitSailSource()private longgetFreeToAllocateMemory()SailSourcegetInferredSailSource()private CloseableIteration<MemStatement,SailException>getMemStatementIterator(MemResource subj, MemIRI pred, MemValue obj, java.lang.Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementList statementList)private MemStatementListgetSmallestStatementList(MemResource subj, MemIRI pred, MemValue obj)ValueFactorygetValueFactory()TheValueFactorythat should be used in association with this.private voidinvalidateCache()private static booleanmemoryIsLow(long freeToAllocateMemory)private booleanprioritiseSnapshotCleaningIfLowOnMemory(boolean prioritiseCleaning)protected voidscheduleSnapshotCleanup()
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
RUNTIME
private static final java.lang.Runtime RUNTIME
-
MAX_MEMORY
private static final long MAX_MEMORY
-
CLEANUP_MAX_MEMORY_THRESHOLD
private static final int CLEANUP_MAX_MEMORY_THRESHOLD
- See Also:
- Constant Field Values
-
CLEANUP_MINIMUM_FREE_MEMORY
private static final int CLEANUP_MINIMUM_FREE_MEMORY
- See Also:
- Constant Field Values
-
CLEANUP_MINIMUM_FREE_MEMORY_RATIO
private static final double CLEANUP_MINIMUM_FREE_MEMORY_RATIO
- See Also:
- Constant Field Values
-
EMPTY_ITERATION
public static final EmptyIteration<MemStatement,SailException> EMPTY_ITERATION
-
EMPTY_TRIPLE_ITERATION
public static final EmptyIteration<MemTriple,SailException> EMPTY_TRIPLE_ITERATION
-
EMPTY_CONTEXT
public static final MemResource[] EMPTY_CONTEXT
-
NULL_CONTEXT
public static final MemResource[] NULL_CONTEXT
-
iteratorCache
private final MemStatementIteratorCache iteratorCache
-
valueFactory
private final MemValueFactory valueFactory
Factory/cache for MemValue objects.
-
statements
private final MemStatementList statements
List containing all available statements.
-
mayHaveInferred
private volatile boolean mayHaveInferred
This gets set to `true` when we add our first inferred statement. If the value is `false` we guarantee that there are no inferred statements in the MemorySailStore. If it is `true` then an inferred statement was added at some point, but we make no guarantees regarding if there still are inferred statements or if they are in the current snapshot.The purpose of this variable is to optimize read operations that only read inferred statements when there are no inferred statements.
-
currentSnapshot
private volatile int currentSnapshot
Identifies the current snapshot.
-
snapshotMonitor
final MemorySailStore.SnapshotMonitor snapshotMonitor
-
namespaceStore
private final MemNamespaceStore namespaceStore
Store for namespace prefix info.
-
txnLockManager
private final java.util.concurrent.locks.ReentrantLock txnLockManager
Lock manager used to prevent concurrent writes.
-
snapshotCleanupThread
private volatile java.lang.Thread snapshotCleanupThread
Cleanup thread that removes deprecated statements when no other threads are accessing this list. SeeescheduleSnapshotCleanup().
-
snapshotCleanupThreadLockObject
private final java.lang.Object snapshotCleanupThreadLockObject
Lock object used to synchronize concurrent access tosnapshotCleanupThread.
-
-
Method Detail
-
getValueFactory
public ValueFactory getValueFactory()
Description copied from interface:SailStoreTheValueFactorythat should be used in association with this.- Specified by:
getValueFactoryin interfaceSailStore- Returns:
- this object's
ValueFactory
-
close
public void close()
Description copied from interface:SailClosableCloses this resource, relinquishing any underlying resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceSailClosable
-
invalidateCache
private void invalidateCache()
-
getEvaluationStatistics
public EvaluationStatistics getEvaluationStatistics()
Description copied from interface:SailStoreUsed bySailSourceConnectionto determine query join order.- Specified by:
getEvaluationStatisticsin interfaceSailStore- Returns:
- a
EvaluationStatisticsthat is aware of the data distribution of thisSailStore.
-
getExplicitSailSource
public SailSource getExplicitSailSource()
- Specified by:
getExplicitSailSourcein interfaceSailStore- Returns:
SailSourceof only explicit statements
-
getInferredSailSource
public SailSource getInferredSailSource()
- Specified by:
getInferredSailSourcein interfaceSailStore- Returns:
SailSourceof only inferred statements
-
createStatementIterator
private CloseableIteration<MemStatement,SailException> createStatementIterator(Resource subj, IRI pred, Value obj, java.lang.Boolean explicit, int snapshot, Resource... contexts) throws java.lang.InterruptedException
Creates a StatementIterator that contains the statements matching the specified pattern of subject, predicate, object, context. Inferred statements are excluded when explicitOnly is set to true . Statements from the null context are excluded when namedContextsOnly is set to true. The returned StatementIterator will assume the specified read mode.- Throws:
java.lang.InterruptedException
-
getMemStatementIterator
private CloseableIteration<MemStatement,SailException> getMemStatementIterator(MemResource subj, MemIRI pred, MemValue obj, java.lang.Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementList statementList) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
getSmallestStatementList
private MemStatementList getSmallestStatementList(MemResource subj, MemIRI pred, MemValue obj)
-
createTripleIterator
private CloseableIteration<MemTriple,SailException> createTripleIterator(Resource subj, IRI pred, Value obj, int snapshot) throws java.lang.InterruptedException
Creates a TripleIterator that contains the triples matching the specified pattern of subject, predicate, object, context.- Throws:
java.lang.InterruptedException
-
cleanSnapshots
protected void cleanSnapshots() throws java.lang.InterruptedExceptionRemoves statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.- Throws:
java.lang.InterruptedException
-
prioritiseSnapshotCleaningIfLowOnMemory
private boolean prioritiseSnapshotCleaningIfLowOnMemory(boolean prioritiseCleaning)
-
memoryIsLow
private static boolean memoryIsLow(long freeToAllocateMemory)
-
getFreeToAllocateMemory
private long getFreeToAllocateMemory()
-
scheduleSnapshotCleanup
protected void scheduleSnapshotCleanup()
-
convertToSailException
private SailException convertToSailException(java.lang.InterruptedException e)
-
-