Search in sources :

Example 6 with StoreConnection

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));
    });
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 7 with StoreConnection

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));
    });
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 8 with StoreConnection

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());
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Example 9 with StoreConnection

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);
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Example 10 with StoreConnection

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

Aggregations

StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)7 Test (org.junit.Test)7 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)4 Location (org.apache.jena.dboe.base.file.Location)2 TDBException (org.apache.jena.tdb2.TDBException)2 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1