use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_03.
@Test
public void store_03() {
StoreConnection sConn = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
Txn.executeWrite(dsg, () -> {
dsg.add(q1);
});
Txn.executeWrite(dsg, () -> {
assertTrue(dsg.contains(q1));
});
try {
Txn.executeWrite(dsg, () -> {
dsg.add(q2);
throw new RuntimeException();
});
fail("Should not get to here!");
} catch (RuntimeException ex) {
}
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(q1));
assertFalse(dsg.contains(q2));
});
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_04.
@Test
public void store_04() {
StoreConnection sConn = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
Txn.executeWrite(dsg, () -> {
dsg.add(q1);
});
Txn.executeWrite(dsg, () -> {
assertTrue(dsg.contains(q1));
});
dsg.begin(ReadWrite.WRITE);
dsg.add(q2);
dsg.abort();
dsg.end();
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(q1));
assertFalse(dsg.contains(q2));
});
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class TestStoreConnectionLock method lock_store_connection_01.
@Test
public void lock_store_connection_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
ProcessFileLock lock = StoreConnection.lockForLocation(dir);
assertFalse(lock.isLockedHere());
StoreConnection sConn = StoreConnection.connectCreate(dir);
assertEquals(dir, sConn.getLocation());
assertEquals(lock, sConn.getLock());
assertTrue(lock.isLockedHere());
StoreConnection.release(dir);
assertFalse(lock.isLockedHere());
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class TestStoreConnectionLock method lock_store_connection_02.
@Test(expected = AlreadyLocked.class)
public void lock_store_connection_02() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
ProcessFileLock lock = StoreConnection.lockForLocation(dir);
lock.lockEx();
StoreConnection sConn = StoreConnection.connectCreate(dir);
}
use of org.apache.jena.tdb2.sys.StoreConnection 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());
}
Aggregations