Package org.eclipse.rdf4j.sail.memory
Class MemorySailStore
java.lang.Object
org.eclipse.rdf4j.sail.memory.MemorySailStore
- All Implemented Interfaces:
AutoCloseable
,SailClosable
,SailStore
An implementation of
SailStore
that keeps committed statements in a MemStatementList
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
private final class
private final class
(package private) static class
SnapshotMonitor 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
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final double
private int
Identifies the current snapshot.static final MemResource[]
static final EmptyIteration
<MemStatement, SailException> static final EmptyIteration
<MemTriple, SailException> private final MemStatementIteratorCache
private static final org.slf4j.Logger
private static final long
private boolean
This gets set to `true` when we add our first inferred statement.private final MemNamespaceStore
Store for namespace prefix info.static final MemResource[]
private static final Runtime
private Thread
Cleanup thread that removes deprecated statements when no other threads are accessing this list.private final Object
Lock object used to synchronize concurrent access tosnapshotCleanupThread
.(package private) final MemorySailStore.SnapshotMonitor
private final MemStatementList
List containing all available statements.private final ReentrantLock
Lock manager used to prevent concurrent writes.private final MemValueFactory
Factory/cache for MemValue objects. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Removes statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.void
close()
Closes this resource, relinquishing any underlying resources.private SailException
private CloseableIteration
<MemStatement, SailException> createStatementIterator
(Resource subj, IRI pred, Value obj, 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.Used bySailSourceConnection
to determine query join order.private long
private CloseableIteration
<MemStatement, SailException> getMemStatementIterator
(MemResource subj, MemIRI pred, MemValue obj, Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementList statementList) private MemStatementList
getSmallestStatementList
(MemResource subj, MemIRI pred, MemValue obj) TheValueFactory
that should be used in association with this.private void
private static boolean
memoryIsLow
(long freeToAllocateMemory) private boolean
prioritiseSnapshotCleaningIfLowOnMemory
(boolean prioritiseCleaning) protected void
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
RUNTIME
-
MAX_MEMORY
private static final long MAX_MEMORY -
CLEANUP_MAX_MEMORY_THRESHOLD
private static final int CLEANUP_MAX_MEMORY_THRESHOLD- See Also:
-
CLEANUP_MINIMUM_FREE_MEMORY
private static final int CLEANUP_MINIMUM_FREE_MEMORY- See Also:
-
CLEANUP_MINIMUM_FREE_MEMORY_RATIO
private static final double CLEANUP_MINIMUM_FREE_MEMORY_RATIO- See Also:
-
EMPTY_ITERATION
-
EMPTY_TRIPLE_ITERATION
-
EMPTY_CONTEXT
-
NULL_CONTEXT
-
iteratorCache
-
valueFactory
Factory/cache for MemValue objects. -
statements
List containing all available statements. -
mayHaveInferred
private volatile boolean mayHaveInferredThis 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 currentSnapshotIdentifies the current snapshot. -
snapshotMonitor
-
namespaceStore
Store for namespace prefix info. -
txnLockManager
Lock manager used to prevent concurrent writes. -
snapshotCleanupThread
Cleanup thread that removes deprecated statements when no other threads are accessing this list. SeeescheduleSnapshotCleanup()
. -
snapshotCleanupThreadLockObject
Lock object used to synchronize concurrent access tosnapshotCleanupThread
.
-
-
Constructor Details
-
MemorySailStore
public MemorySailStore(boolean debug)
-
-
Method Details
-
getValueFactory
Description copied from interface:SailStore
TheValueFactory
that should be used in association with this.- Specified by:
getValueFactory
in interfaceSailStore
- Returns:
- this object's
ValueFactory
-
close
public void close()Description copied from interface:SailClosable
Closes this resource, relinquishing any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSailClosable
-
invalidateCache
private void invalidateCache() -
getEvaluationStatistics
Description copied from interface:SailStore
Used bySailSourceConnection
to determine query join order.- Specified by:
getEvaluationStatistics
in interfaceSailStore
- Returns:
- a
EvaluationStatistics
that is aware of the data distribution of thisSailStore
.
-
getExplicitSailSource
- Specified by:
getExplicitSailSource
in interfaceSailStore
- Returns:
SailSource
of only explicit statements
-
getInferredSailSource
- Specified by:
getInferredSailSource
in interfaceSailStore
- Returns:
SailSource
of only inferred statements
-
createStatementIterator
private CloseableIteration<MemStatement,SailException> createStatementIterator(Resource subj, IRI pred, Value obj, Boolean explicit, int snapshot, Resource... contexts) throws 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:
InterruptedException
-
getMemStatementIterator
private CloseableIteration<MemStatement,SailException> getMemStatementIterator(MemResource subj, MemIRI pred, MemValue obj, Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementList statementList) throws InterruptedException - Throws:
InterruptedException
-
getSmallestStatementList
-
createTripleIterator
private CloseableIteration<MemTriple,SailException> createTripleIterator(Resource subj, IRI pred, Value obj, int snapshot) throws InterruptedException Creates a TripleIterator that contains the triples matching the specified pattern of subject, predicate, object, context.- Throws:
InterruptedException
-
cleanSnapshots
Removes statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.- Throws:
InterruptedException
-
prioritiseSnapshotCleaningIfLowOnMemory
private boolean prioritiseSnapshotCleaningIfLowOnMemory(boolean prioritiseCleaning) -
memoryIsLow
private static boolean memoryIsLow(long freeToAllocateMemory) -
getFreeToAllocateMemory
private long getFreeToAllocateMemory() -
scheduleSnapshotCleanup
protected void scheduleSnapshotCleanup() -
convertToSailException
-