Search in sources :

Example 16 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class AbstractStoreConnections method store_7.

@Test
public void store_7() {
    // No transaction, plain update, then transaction.
    // This tests that the dataset is sync'ed when going into transactional mode.
    boolean nonTxnData = true;
    StoreConnection sConn = getStoreConnection();
    Location loc = sConn.getLocation();
    DatasetGraph dsg = sConn.getBaseDataset();
    if (nonTxnData) {
        dsg.add(q);
        TDB.sync(dsg);
        assertTrue(dsg.contains(q));
    }
    DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
    if (nonTxnData)
        assertTrue(dsgTxn.contains(q));
    dsgTxn.add(q1);
    assertTrue(dsgTxn.contains(q1));
    if (nonTxnData)
        assertTrue(dsgTxn.contains(q));
    dsgTxn.commit();
    dsgTxn.end();
    // Should have flushed to disk.
    if (nonTxnData) {
        sConn.forceRecoverFromJournal();
        assertTrue(dsg.contains(q));
    }
    assertTrue(dsg.contains(q1));
    // release via the transactional machinery
    StoreConnection.release(loc);
    sConn = null;
    StoreConnection sConn2 = StoreConnection.make(loc);
    DatasetGraph dsg2 = sConn2.getBaseDataset();
    if (nonTxnData)
        assertTrue(dsg2.contains(q));
    assertTrue(dsg2.contains(q1));
    DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ);
    if (nonTxnData)
        assertTrue(dsgTxn2.contains(q));
    assertTrue(dsgTxn2.contains(q1));
    dsgTxn2.end();
    // Check API methods work.
    Dataset ds = TDBFactory.createDataset(loc);
    ds.begin(ReadWrite.READ);
    Model m = (q.isDefaultGraph() ? ds.getDefaultModel() : ds.getNamedModel("g"));
    assertEquals(nonTxnData ? 2 : 1, m.size());
    ds.end();
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) Dataset(org.apache.jena.query.Dataset) DatasetGraphTxn(org.apache.jena.tdb.transaction.DatasetGraphTxn) Model(org.apache.jena.rdf.model.Model) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 17 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class AbstractStoreConnections method store_5.

@Test
public void store_5() {
    // No transaction. Make sure StoreConnection.release cleans up OK.
    StoreConnection sConn = getStoreConnection();
    Location loc = sConn.getLocation();
    DatasetGraph dsg = sConn.getBaseDataset();
    dsg.add(q);
    assertTrue(dsg.contains(q));
    StoreConnection.release(loc);
    sConn = StoreConnection.make(loc);
    dsg = sConn.getBaseDataset();
    assertTrue(dsg.contains(q));
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 18 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class TestLocationLockStoreConnection method location_lock_store_connection_01.

@Test
public void location_lock_store_connection_01() {
    Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
    LocationLock lock = dir.getLock();
    Assert.assertTrue(lock.canLock());
    Assert.assertFalse(lock.isLocked());
    Assert.assertFalse(lock.isOwned());
    Assert.assertTrue(lock.canObtain());
    // Creating a StoreConnection on the location will obtain the lock
    StoreConnection.make(dir);
    Assert.assertTrue(lock.isLocked());
    Assert.assertTrue(lock.isOwned());
    Assert.assertTrue(lock.canObtain());
    // Releasing the connection releases the lock
    StoreConnection.release(dir);
    Assert.assertFalse(lock.isLocked());
    Assert.assertFalse(lock.isOwned());
    Assert.assertTrue(lock.canObtain());
}
Also used : LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location) Test(org.junit.Test)

Example 19 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class StoreConnection method reset.

/** Stop managing all locations. Use with great care. */
public static synchronized void reset() {
    // Copy to avoid potential CME.
    Set<Location> x = new HashSet<>(cache.keySet());
    for (Location loc : x) expel(loc, true);
    cache.clear();
}
Also used : HashSet(java.util.HashSet) Location(org.apache.jena.tdb.base.file.Location)

Example 20 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class dumpbpt method exec.

@Override
protected void exec() {
    List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes);
    List<String> quadIndexes = Arrays.asList(Names.quadIndexes);
    Location loc = modLocation.getLocation();
    // The name is the order.
    for (String indexName : super.getPositional()) {
        String primary;
        if (indexName.length() == 3) {
            primary = Names.primaryIndexTriples;
        } else if (indexName.length() == 4) {
            primary = Names.primaryIndexQuads;
        } else {
            cmdError("Wrong length: " + indexName);
            primary = null;
        }
        int keySubLen = SystemTDB.SizeOfNodeId;
        int keyUnitLen = indexName.length();
        int keyLength = keySubLen * keyUnitLen;
        int valueLength = 0;
        RecordFactory rf = new RecordFactory(keyLength, valueLength);
        RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf);
        BPlusTree bpt = (BPlusTree) rIndex;
        if (false) {
            System.out.println("---- Index structure");
            bpt.dump();
        }
        if (true) {
            System.out.println("---- Index contents");
            Iterator<Record> iter = bpt.iterator();
            if (!iter.hasNext())
                System.out.println("<<Empty>>");
            for (; iter.hasNext(); ) {
                Record r = iter.next();
                printRecord("", System.out, r, keyUnitLen);
            }
        }
        // Check.
        Iterator<Record> iterCheck = bpt.iterator();
        Record r1 = null;
        int i = 0;
        for (; iterCheck.hasNext(); ) {
            Record r2 = iterCheck.next();
            i++;
            if (r1 != null) {
                if (!Record.keyLT(r1, r2)) {
                    System.err.println("key error@ " + i);
                    printRecord("  ", System.err, r1, keyUnitLen);
                    printRecord("  ", System.err, r2, keyUnitLen);
                }
            }
            r1 = r2;
        }
        if (false) {
            // Dump in tuple order.
            TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName, rIndex.getRecordFactory(), rIndex);
            if (true) {
                System.out.println("---- Tuple contents");
                Iterator<Tuple<NodeId>> iter2 = tupleIndex.all();
                if (!iter2.hasNext())
                    System.out.println("<<Empty>>");
                for (; iter2.hasNext(); ) {
                    Tuple<NodeId> row = iter2.next();
                    System.out.println(row);
                }
            }
        }
    }
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) RangeIndex(org.apache.jena.tdb.index.RangeIndex) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) BPlusTree(org.apache.jena.tdb.index.bplustree.BPlusTree) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Location(org.apache.jena.tdb.base.file.Location) ModLocation(tdb.cmdline.ModLocation)

Aggregations

Location (org.apache.jena.tdb.base.file.Location)29 Test (org.junit.Test)16 BaseTest (org.apache.jena.atlas.junit.BaseTest)9 LocationLock (org.apache.jena.tdb.base.file.LocationLock)8 ConfigTest (org.apache.jena.tdb.ConfigTest)6 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 StoreConnection (org.apache.jena.tdb.StoreConnection)4 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)4 Record (org.apache.jena.tdb.base.record.Record)3 StoreParams (org.apache.jena.tdb.setup.StoreParams)3 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 Dataset (org.apache.jena.query.Dataset)2 VocabTDB.pLocation (org.apache.jena.tdb.assembler.VocabTDB.pLocation)2 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)2 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)2