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());
}
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");
}
Aggregations