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 ofSailStore
that keeps committed statements in aMemStatementList
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
MemorySailStore.MemorySailDataset
private class
MemorySailStore.MemorySailSink
private class
MemorySailStore.MemorySailSource
(package private) static class
MemorySailStore.SnapshotMonitor
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
Fields Modifier and Type Field Description private static int
CLEANUP_MAX_MEMORY_THRESHOLD
private static int
CLEANUP_MINIMUM_FREE_MEMORY
private static double
CLEANUP_MINIMUM_FREE_MEMORY_RATIO
private int
currentSnapshot
Identifies the current snapshot.static MemResource[]
EMPTY_CONTEXT
static EmptyIteration<MemStatement,SailException>
EMPTY_ITERATION
static EmptyIteration<MemTriple,SailException>
EMPTY_TRIPLE_ITERATION
private MemStatementIteratorCache
iteratorCache
private static org.slf4j.Logger
logger
private static long
MAX_MEMORY
private boolean
mayHaveInferred
This gets set to `true` when we add our first inferred statement.private MemNamespaceStore
namespaceStore
Store for namespace prefix info.static MemResource[]
NULL_CONTEXT
private static java.lang.Runtime
RUNTIME
private java.lang.Thread
snapshotCleanupThread
Cleanup thread that removes deprecated statements when no other threads are accessing this list.private java.lang.Object
snapshotCleanupThreadLockObject
Lock object used to synchronize concurrent access tosnapshotCleanupThread
.(package private) MemorySailStore.SnapshotMonitor
snapshotMonitor
private MemStatementList
statements
List containing all available statements.private java.util.concurrent.locks.ReentrantLock
txnLockManager
Lock manager used to prevent concurrent writes.private MemValueFactory
valueFactory
Factory/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 void
cleanSnapshots()
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
convertToSailException(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.EvaluationStatistics
getEvaluationStatistics()
Used bySailSourceConnection
to determine query join order.SailSource
getExplicitSailSource()
private long
getFreeToAllocateMemory()
SailSource
getInferredSailSource()
private CloseableIteration<MemStatement,SailException>
getMemStatementIterator(MemResource subj, MemIRI pred, MemValue obj, java.lang.Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementList statementList)
private MemStatementList
getSmallestStatementList(MemResource subj, MemIRI pred, MemValue obj)
ValueFactory
getValueFactory()
TheValueFactory
that should be used in association with this.private void
invalidateCache()
private static boolean
memoryIsLow(long freeToAllocateMemory)
private boolean
prioritiseSnapshotCleaningIfLowOnMemory(boolean prioritiseCleaning)
protected void
scheduleSnapshotCleanup()
-
-
-
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: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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceSailClosable
-
invalidateCache
private void invalidateCache()
-
getEvaluationStatistics
public EvaluationStatistics 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
public SailSource getExplicitSailSource()
- Specified by:
getExplicitSailSource
in interfaceSailStore
- Returns:
SailSource
of only explicit statements
-
getInferredSailSource
public SailSource getInferredSailSource()
- Specified by:
getInferredSailSource
in interfaceSailStore
- Returns:
SailSource
of 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.InterruptedException
Removes 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)
-
-