Search in sources :

Example 6 with TDB2

use of org.apache.jena.tdb2.TDB2 in project jena by apache.

the class DatabaseOps method compact.

// XXX Later - switch in a recording dataset, not block writers, and reply after
// switch over before releasing the new dataset to the container.
// Maybe copy indexes and switch the DSG over (drop switchable).
/**
 * Copy the latest version from one location to another.
 */
private static void compact(DatasetGraphSwitchable container, Location loc1, Location loc2) {
    if (loc1.isMem() || loc2.isMem())
        throw new TDBException("Compact involves a memory location: " + loc1 + " : " + loc2);
    copyFiles(loc1, loc2);
    StoreConnection srcConn = StoreConnection.connectExisting(loc1);
    if (srcConn == null)
        throw new TDBException("No database at location : " + loc1);
    if (!(container.get() instanceof DatasetGraphTDB))
        throw new TDBException("Not a TDB2 database in DatasetGraphSwitchable");
    DatasetGraphTDB dsgCurrent = (DatasetGraphTDB) container.get();
    if (!dsgCurrent.getLocation().equals(loc1))
        throw new TDBException("Inconsistent locations for base : " + dsgCurrent.getLocation() + " , " + dsgCurrent.getLocation());
    DatasetGraphTDB dsgBase = srcConn.getDatasetGraphTDB();
    if (dsgBase != dsgCurrent)
        throw new TDBException("Inconsistent datasets : " + dsgCurrent.getLocation() + " , " + dsgBase.getLocation());
    TransactionalSystem txnSystem = dsgBase.getTxnSystem();
    TransactionCoordinator txnMgr = dsgBase.getTxnSystem().getTxnMgr();
    // Stop update.  On exit there are no writers and none will start until switched over.
    txnMgr.tryBlockWriters();
    // txnMgr.begin(WRITE, false) will now bounce.
    // Copy the latest generation.
    DatasetGraphTDB dsgCompact = StoreConnection.connectCreate(loc2).getDatasetGraphTDB();
    CopyDSG.copy(dsgBase, dsgCompact);
    TransactionCoordinator txnMgr2 = dsgCompact.getTxnSystem().getTxnMgr();
    txnMgr2.startExclusiveMode();
    txnMgr.startExclusiveMode();
    // Switch.
    if (!container.change(dsgCurrent, dsgCompact)) {
        Log.warn(DatabaseOps.class, "Inconistent: old datasetgraph not as expected");
        container.set(dsgCompact);
    }
    txnMgr2.finishExclusiveMode();
    // New database running.
    // Clean-up.
    // txnMgr.finishExclusiveMode();
    // Don't call : txnMgr.startWriters();
    StoreConnection.release(dsgBase.getLocation());
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) TransactionalSystem(org.apache.jena.dboe.transaction.txn.TransactionalSystem) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 7 with TDB2

use of org.apache.jena.tdb2.TDB2 in project jena by apache.

the class SpotTDB2 method checkStorageArea.

/**
 * Check all files exist for a TDB2 database, or the area is empty (and so a new
 * database can be created in the location). Throw {@link TDBException} is a file
 * is missing.
 */
private static void checkStorageArea(Location location) {
    if (location.isMem())
        return;
    if (isEmpty(location))
        return;
    // Journal, fixed name.
    validate(location, Names.journalFileBase, Names.extJournal);
    // Places for StoreParams: location or default
    StoreParams params = getStoreParams(location);
    // Check for indexes
    containsIndex(params.getPrimaryIndexTriples(), params.getTripleIndexes());
    validateBPT(location, params.getTripleIndexes());
    containsIndex(params.getPrimaryIndexQuads(), params.getTripleIndexes());
    validateBPT(location, params.getQuadIndexes());
    // prefixes. GPU
    containsIndex(params.getPrimaryIndexPrefix(), params.getPrefixIndexes());
    // GPU is not in files "GPU"
    // Filename of GPU.
    validateBPT(location, params.getPrefixIndexes());
    // ---- Node tables.
    /*
         * nodes.bpt
         * nodes.dat
         * nodes-data.bdf
         * nodes-data.obj
         */
    validateBPT(location, params.getNodeTableBaseName());
    validateDAT(location, params.getNodeTableBaseName() + "-data");
    /*
         * prefixes...
         */
    // XXX validateBPT(location, params.getPrefixTableBaseName());
    validateBPT(location, params.getPrefixTableBaseName());
    validateDAT(location, params.getPrefixTableBaseName() + "-data");
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 TDBException (org.apache.jena.tdb2.TDBException)2 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)2 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)2 ModDataset (arq.cmdline.ModDataset)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 CmdException (org.apache.jena.cmd.CmdException)1 Location (org.apache.jena.dboe.base.file.Location)1 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 JenaException (org.apache.jena.shared.JenaException)1 NodeValue (org.apache.jena.sparql.expr.NodeValue)1 VocabTDB2.pLocation (org.apache.jena.tdb2.assembler.VocabTDB2.pLocation)1 StoreParams (org.apache.jena.tdb2.params.StoreParams)1 GraphTDB (org.apache.jena.tdb2.store.GraphTDB)1 GraphViewSwitchable (org.apache.jena.tdb2.store.GraphViewSwitchable)1