public class BigdataSail extends SailBase implements org.openrdf.sail.Sail
Sesame 2.x
integration.
Read-write operations use getConnection()
to obtain a mutable view.
This delegates to either getUnisolatedConnection()
or
getReadWriteConnection()
depending on how the Sail is configured.
Concurrent unisolated writers are supported if group commit is enabled, but
at most one unisolated writer will execute against a given Sail instance at a
time - other writers will be serialized. See
getUnisolatedConnection()
for more information on how to enable
group commit and how to write code that supports group commit.
Concurrent readers are possible, and can be very efficient. However, readers
MUST use a database commit point corresponding to a desired state of the
store, e.g., after loading some data set and (optionally) after computing the
closure of that data set. Use getReadOnlyConnection()
to obtain a
read-only view of the database as of the last commit time, or
getReadOnlyConnection(long)
to obtain a read-only view of the
database as of some other historical point. These connections are safe to use
concurrently with the unisolated connection from getConnection()
.
Concurrent fully isolated read/write transactions against the same Sail are
also implemented in the bigdata SAIL. To turn on read/write transactions, use
the option BigdataSail.Options.ISOLATABLE_INDICES
. If this option is set to true,
then getConnection()
will return an isolated read/write view of the
database. Multiple concurrent read/write transactions are allowed, and the
database can resolve add/add conflicts between transactions. Unlike group
commit, these fully isolated read/write transactions will in fact execute
concurrently against the same Sail instance (rather than being serialized).
However, there is additional overhead for fully isolated read/write
transactions and graph update patterns can lead to unreconcilable conflicts
during updates (in which case one transaction will be a failed during the
validation phase). The highest throughput is generally obtained using
getUnisolatedConnection()
in which case you do not need to enabled
BigdataSail.Options.ISOLATABLE_INDICES
.
The BigdataSail
may be configured as as to provide a triple store
with statement-level provenance using statement identifiers. See
AbstractTripleStore.Options#STATEMENT_IDENTIFIERS
and
Reification Done Right .
Quads may be enabled using AbstractTripleStore.Options#QUADS
.
However, note that BigdataSail.Options.TRUTH_MAINTENANCE
is not supported for
AbstractTripleStore.Options#QUADS
at this time. This may change in
the future once we decide how to handle eager materialization of entailments
with multiple named graphs. The basic problem is that:
merge(closure(graphA), closure(graphB))
IS NOT EQUALS TO
closure(merge(graphA, graphB))
There are two ways to handle this. One is to compute all inferences at query time, in which case we are not doing eager materialization and therefore we are not using Truth Maintenance. The other is to punt and use the merge of their individual closures.
Modifier and Type | Class and Description |
---|---|
class |
BigdataSail.BigdataSailConnection
Inner class implements the
SailConnection . |
static interface |
BigdataSail.Options
Additional parameters understood by the Sesame 2.x SAIL implementation.
|
static class |
BigdataSail.UnisolatedCallable<T>
Abstract base class permits some patterns in which the
Callable
owns the locks required to obtain the unisolated connection. |
Modifier and Type | Field and Description |
---|---|
static org.openrdf.model.URI |
NULL_GRAPH
Sesame has the notion of a "null" graph which we use for the quad store
mode.
|
CONNECTION_TIMEOUT, connectionTimeOut, DEFAULT_CONNECTION_TIMEOUT, initializationLock, logger
Constructor and Description |
---|
BigdataSail()
Create or re-open a database instance configured using defaults.
|
BigdataSail(AbstractTripleStore database)
Constructor used to wrap an existing
AbstractTripleStore
instance. |
BigdataSail(AbstractTripleStore database,
IIndexManager mainIndexManager)
Core ctor.
|
BigdataSail(Properties properties)
Create or open a database instance configured using the specified
properties.
|
BigdataSail(String namespace,
IIndexManager indexManager)
Constructor used when the namespace and index manager are known (standard
use case).
|
BigdataSail(String namespace,
IIndexManager indexManager,
IIndexManager mainIndexManager)
Core constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
__tearDownUnitTest()
DO NOT INVOKE FROM APPLICATION CODE - this method
deletes the KB instance and destroys the backing database instance.
|
protected void |
assertOpenSail() |
static void |
checkProperties(Properties properties)
Check properties to make sure that they are consistent.
|
void |
create(Properties properties)
Create a the configured namespace.
|
void |
destroy()
Destroy the configured namespace.
|
boolean |
exists()
Return true iff the namespace exists at the moment when this check is
performed.
|
protected void |
finalize()
Invokes
shutDown() . |
BigdataSail.BigdataSailConnection |
getConnection() |
protected org.openrdf.sail.NotifyingSailConnection |
getConnectionInternal()
Return a read-write
SailConnection . |
IIndexManager |
getIndexManager()
The index manager associated with the database (when there is a focus
store and a main database, then this is the focus store index manager).
|
String |
getNamespace()
Return the blazegraph namespace associated with the
BigdataSail . |
QueryEngine |
getQueryEngine() |
BigdataSail.BigdataSailConnection |
getReadOnlyConnection()
Return a read-only connection based on the last commit point.
|
BigdataSail.BigdataSailConnection |
getReadOnlyConnection(long timestamp)
Obtain a read-historical view that reads from the specified commit point.
|
BigdataSail.BigdataSailConnection |
getReadWriteConnection()
Return a connection backed by a read-write transaction.
|
protected ITransactionService |
getTxService()
Return the
ITransactionService . |
BigdataSail.BigdataSailConnection |
getUnisolatedConnection()
Return an unisolated connection to the database.
|
<T> T |
getUnisolatedConnectionLocksAndRunLambda(BigdataSail.UnisolatedCallable<T> lambda)
Obtain the locks required by the unisolated connection and invoke the
caller's lambda.
|
org.openrdf.model.ValueFactory |
getValueFactory()
|
protected void |
initializeInternal()
Do store-specific operations to initialize the store.
|
boolean |
isOpen()
|
boolean |
isWritable()
Return false iff the Sail can not provide a writable connection.
|
void |
shutDown() |
protected void |
shutDownInternal()
If the backing database was created/opened by the
BigdataSail
then it is closed. |
connectionClosed, debugEnabled, getDataDir, initialize, isInitialized, manageConnection, setDataDir, toString
public static final transient org.openrdf.model.URI NULL_GRAPH
DATASET
is not specified, then all contexts are
queried and you will see statements from the "null" graph as well as from
any other context.
BigdataSail.BigdataSailConnection.getStatements(Resource, URI, Value, boolean, Resource...)
will return statements from the "null" graph if the context is either
unbound or is an array whose sole element is null
.public BigdataSail()
public BigdataSail(Properties properties)
BigdataSail.Options
public BigdataSail(AbstractTripleStore database)
AbstractTripleStore
instance.
Note: Since BLZG-2041, this delegates through to the core constructor which accepts (namespace, IIndexManager).
database
- The instance.public BigdataSail(AbstractTripleStore database, IIndexManager mainIndexManager)
To create a BigdataSail
backed by an IBigdataFederation
use the ScaleOutTripleStore
ctor and then
AbstractTripleStore.create()
the triple store if it does not
exist.
Note: Since BLZG-2041, this delegates through to the core constructor which accepts (namespace, IIndexManager).
database
- An existing AbstractTripleStore
.mainIndexManager
- When database is a TempTripleStore
, this is the
IIndexManager
used to resolve the
QueryEngine
. Otherwise it must be the same object as
the database.public BigdataSail(String namespace, IIndexManager indexManager)
namespace
- The namespace.indexManager
- The index manager (typically a Journal
).public BigdataSail(String namespace, IIndexManager indexManager, IIndexManager mainIndexManager)
Note: Scale-out is shard-wise ACID.
To create a BigdataSail
backed by an IBigdataFederation
use the ScaleOutTripleStore
ctor and then
AbstractTripleStore.create()
the triple store if it does not
exist. See CreateKBTask
which encapsulates this.
namespace
- The namespace.indexManager
- The index manager on which the data is stored.mainIndexManager
- Iff the data is stored on a TempTripleStore
then this is the main index manager and will be used to locate the QueryEngine
.BigdataSail should not locate the AbstractTripleStore until a connection is requested
public String getNamespace()
BigdataSail
.BigdataSail.Options.NAMESPACE
,
BigdataSail.getUnisolatedConnection() encapsulation
public IIndexManager getIndexManager()
BigdataSail.getUnisolatedConnection() encapsulation
public static void checkProperties(Properties properties) throws UnsupportedOperationException
properties
- The properties.UnsupportedOperationException
protected void assertOpenSail()
IllegalStateException
- if the BigdataSail
has not been SailBase.initialize()
d
or has been shutDown()
.public boolean isOpen()
public void create(Properties properties) throws InterruptedException, ExecutionException
properties
- The configuration properties for the namespace.ExecutionException
InterruptedException
BigdataSail.Options.NAMESPACE
,
(BigdataSail should not locate the AbstractTripleStore until a connection is requested)
public void destroy() throws org.openrdf.sail.SailException, InterruptedException, ExecutionException
org.openrdf.sail.SailException
ExecutionException
InterruptedException
BigdataSail.Options.NAMESPACE
,
(BigdataSail should not locate the AbstractTripleStore until a connection is requested)
public boolean exists()
Note: It is not possible to use this with any guarantees that the namespace still exists once control is returned to the caller unless the caller is holding an unisolated connection.
(BigdataSail should not locate the AbstractTripleStore until a connection is requested)
protected void initializeInternal() throws org.openrdf.sail.SailException
SailBase
initializeInternal
in class SailBase
IllegalStateException
- if the sail is already open.org.openrdf.sail.SailException
protected void finalize() throws Throwable
shutDown()
.public void shutDown() throws org.openrdf.sail.SailException
protected void shutDownInternal() throws org.openrdf.sail.SailException
BigdataSail
then it is closed. Otherwise this is a NOP.shutDownInternal
in class SailBase
org.openrdf.sail.SailException
public void __tearDownUnitTest()
public final org.openrdf.model.ValueFactory getValueFactory()
getValueFactory
in interface org.openrdf.sail.Sail
public final boolean isWritable() throws org.openrdf.sail.SailException
isWritable
in interface org.openrdf.sail.Sail
org.openrdf.sail.SailException
(BigdataSail should not locate the AbstractTripleStore until a connection is requested)
protected org.openrdf.sail.NotifyingSailConnection getConnectionInternal() throws org.openrdf.sail.SailException
SailConnection
. This is used for both
read-write transactions and the UNISOLATED connection.
Note: There is only one UNISOLATED connection and, when requested, this method will block until that connection is available.
getConnectionInternal
in class SailBase
org.openrdf.sail.SailException
for a non-blocking, read-only connection.
public BigdataSail.BigdataSailConnection getConnection() throws org.openrdf.sail.SailException
If the triple store was provisioned to support full read/write
transactions then this is delegated to getReadWriteConnection()
.
Otherwise, is delegated to getUnisolatedConnection()
which
returns the unisolated view of the database. Note that truth maintenance
requires only one connection at a time and is therefore not compatible
with full read/write transactions.
The correct pattern for obtaining an updatable connection, doing work with that connection, and committing or rolling back that update is as follows.
BigdataSailConnection conn = null; boolean ok = false; try { conn = sail.getConnection(); doWork(conn); conn.commit(); ok = true; } finally { if (conn != null) { if (!ok) { conn.rollback(); } conn.close(); } }This pattern can also be used with
getUnisolatedConnection()
.getConnection
in interface org.openrdf.sail.Sail
getConnection
in class SailBase
org.openrdf.sail.SailException
public BigdataSail.BigdataSailConnection getUnisolatedConnection() throws InterruptedException
Journal
and shard-wise
ACID when used with an IBigdataFederation
.
If group commit
is enabled and you use the either the REST API or the
AbstractApiTask.submitApiTask(IIndexManager, com.bigdata.rdf.task.IApiTask)
pattern to submit tasks, then concurrent unisolated connections will be
granted for different namespaces and multiple unisolated connections for
the same namespace MAY be melded into the same commit group (whether they
are or not depends on the timing of the tasks and whether they are being
submitted by a single client thread or by a pool of clients).
In this mode the application decides when the database will go through a
commit point. In order to guarantee that operations against the unisolated
connection are ACID, only one unisolated connection is permitted at a time
for a Journal
. If there is an open unisolated connection against a
local Journal
, then the open connection must be closed before a
new connection can be returned by this method.
This constraint that there can be only one unisolated connection is not enforced in scale-out since unisolated operations in scale-out are only shard-wise ACID.
The correct pattern for obtaining an updatable connection, doing work with that connection, and committing or rolling back that update is as follows.
BigdataSailConnection conn = null; boolean ok = false; try { conn = sail.getUnisolatedConnection(); doWork(conn); conn.commit(); ok = true; } finally { if (conn != null) { if (!ok) { conn.rollback(); } conn.close(); } }
InterruptedException
getConnection()
,
Group
Commit (wiki) public <T> T getUnisolatedConnectionLocksAndRunLambda(BigdataSail.UnisolatedCallable<T> lambda) throws Exception
lambda
- The caller's lambdaException
public BigdataSail.BigdataSailConnection getReadOnlyConnection()
public BigdataSail.BigdataSailConnection getReadOnlyConnection(long timestamp)
timestamp
- The commit point.public BigdataSail.BigdataSailConnection getReadWriteConnection() throws IOException, InterruptedException
InterruptedException
DatasetNotFoundException
UnsupportedOperationException
- unless BigdataSail.Options.ISOLATABLE_INDICES
was specified when
the backing triple store instance was provisioned.IOException
protected ITransactionService getTxService()
ITransactionService
.public QueryEngine getQueryEngine()
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.