Search in sources :

Example 21 with Location

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

the class ProcBuildIndexX method indexBuilder.

private static long indexBuilder(DatasetGraph dsg, InputStream input, String indexName) {
    long tickPoint = BulkLoaderX.DataTick;
    int superTick = BulkLoaderX.DataSuperTick;
    // Location of storage, not the DB.
    DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
    Location location = dsgtdb.getLocation();
    int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
    int valueLength = 0;
    // The name is the order.
    String primary = indexName;
    String primaryOrder;
    int dftKeyLength;
    int dftValueLength;
    int tupleLength = indexName.length();
    TupleIndex index;
    if (tupleLength == 3) {
        primaryOrder = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
        // Find index.
        index = findIndex(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else if (tupleLength == 4) {
        primaryOrder = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
        index = findIndex(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else {
        throw new TDBException("Index name: " + indexName);
    }
    TupleMap colMap = TupleMap.create(primaryOrder, indexName);
    int readCacheSize = 10;
    int writeCacheSize = 100;
    int blockSize = SystemTDB.BlockSize;
    RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
    int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
    BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
    int blockSizeNodes = blockSize;
    int blockSizeRecords = blockSize;
    FileSet destination = new FileSet(location, indexName);
    BufferChannel blkState = FileFactory.createBufferChannel(destination, Names.extBptState);
    BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.extBptTree, blockSizeNodes, readCacheSize, writeCacheSize);
    BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.extBptRecords, blockSizeRecords, readCacheSize, writeCacheSize);
    int rowBlock = 1000;
    Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
    // ProgressMonitor.
    ProgressMonitor monitor = ProgressMonitorOutput.create(BulkLoaderX.LOG_Index, indexName, tickPoint, superTick);
    ProgressIterator<Record> iter2 = new ProgressIterator<>(iter, monitor);
    monitor.start();
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter2, bptParams, recordFactory, blkState, blkMgrNodes, blkMgrRecords);
    bpt2.close();
    monitor.finish();
    // [BULK] End stage.
    long count = monitor.getTicks();
    return count;
}
Also used : BPlusTreeParams(org.apache.jena.dboe.trans.bplustree.BPlusTreeParams) FileSet(org.apache.jena.dboe.base.file.FileSet) TDBException(org.apache.jena.tdb2.TDBException) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) ProgressIterator(org.apache.jena.system.progress.ProgressIterator) ProgressMonitor(org.apache.jena.system.progress.ProgressMonitor) RecordFactory(org.apache.jena.dboe.base.record.RecordFactory) BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) Record(org.apache.jena.dboe.base.record.Record) TupleIndex(org.apache.jena.tdb2.store.tupletable.TupleIndex) BPlusTree(org.apache.jena.dboe.trans.bplustree.BPlusTree) Location(org.apache.jena.dboe.base.file.Location)

Example 22 with Location

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

the class ProcIngestDataX method getDatasetGraph.

private static DatasetGraph getDatasetGraph(String location) {
    Location loc = Location.create(location);
    // Ensure reset
    DatasetGraph dsg0 = DatabaseMgr.connectDatasetGraph(location);
    TDBInternal.expel(dsg0);
    StoreParams storeParams = StoreParams.getDftStoreParams();
    if (true) {
        storeParams = StoreParams.builder(storeParams).node2NodeIdCacheSize(10_000_000).build();
    }
    DatasetGraph dsg = DatabaseConnection.connectCreate(loc, storeParams).getDatasetGraph();
    StoreParams storeParamsActual = TDBInternal.getDatasetGraphTDB(dsg).getStoreParams();
    // FmtLog.info(LOG, "NodeId to Node cache size: %,d", storeParamsActual.getNodeId2NodeCacheSize());
    return dsg;
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 23 with Location

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

the class TestTDBFactory method testTDBFactory2DS_3.

@Test
public void testTDBFactory2DS_3() {
    TDBInternal.reset();
    TDBInternal.reset();
    String DIRx = ConfigTest.getCleanDir();
    Location DIR = Location.create(DIRx);
    try {
        Dataset ds1 = TDB2Factory.connectDataset(DIR);
        Dataset ds2 = TDB2Factory.connectDataset(DIR);
        Txn.executeWrite(ds1, () -> {
            ds1.getDefaultModel().add(s1, p, o1);
        });
        Txn.executeRead(ds2, () -> {
            assertTrue(ds2.getDefaultModel().contains(s1, p, o1));
        });
    } finally {
        FileOps.clearDirectory(DIRx);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Example 24 with Location

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

the class DatabaseConnection method internalReset.

/**
 * Stop managing all locations.
 * Use with extreme care.
 * This is intended to support internal testing.
 */
public static synchronized void internalReset() {
    // Copy to avoid potential CME.
    Set<Location> x = Set.copyOf(cache.keySet());
    for (Location loc : x) internalExpel(loc, true);
    if (!cache.isEmpty())
        Log.error(DatabaseConnection.class, "DatabaseConnection: Expected the cache to be empty");
    cache.clear();
}
Also used : Location(org.apache.jena.dboe.base.file.Location)

Example 25 with Location

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

the class DatabaseOps method compact.

public static void compact(DatasetGraphSwitchable container, boolean shouldDeleteOld) {
    checkSupportsAdmin(container);
    synchronized (compactionLock) {
        Path base = container.getContainerPath();
        Path db1 = findLocation(base, dbPrefix);
        if (db1 == null)
            throw new TDBException("No location: (" + base + ", " + dbPrefix + ")");
        Location loc1 = IO_DB.asLocation(db1);
        // -- Checks
        Location loc1a = ((DatasetGraphTDB) container.get()).getLocation();
        if (loc1a.isMem()) {
        }
        if (!loc1a.exists())
            throw new TDBException("No such location: " + loc1a);
        // Is this the same database location?
        if (!loc1.equals(loc1a))
            throw new TDBException("Inconsistent (not latest?) : " + loc1a + " : " + loc1);
        // -- Checks
        // Version
        int v = IO_DB.extractIndex(db1.getFileName().toString(), dbPrefix, SEP);
        String next = FilenameUtils.filename(dbPrefix, SEP, v + 1);
        Path db2 = db1.getParent().resolve(next);
        IOX.createDirectory(db2);
        Location loc2 = IO_DB.asLocation(db2);
        LOG.debug(String.format("Compact %s -> %s\n", db1.getFileName(), db2.getFileName()));
        compact(container, loc1, loc2);
        if (shouldDeleteOld) {
            Path loc1Path = IO_DB.asPath(loc1);
            LOG.debug("Deleting old database after successful compaction (old db path='" + loc1Path + "')...");
            try (Stream<Path> walk = Files.walk(loc1Path)) {
                walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
            } catch (IOException ex) {
                throw IOX.exception(ex);
            }
        }
    }
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Aggregations

Location (org.apache.jena.dboe.base.file.Location)29 Test (org.junit.Test)12 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)10 ConfigTest (org.apache.jena.tdb2.ConfigTest)7 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)7 StoreParams (org.apache.jena.tdb2.params.StoreParams)4 Dataset (org.apache.jena.query.Dataset)3 TDBException (org.apache.jena.tdb2.TDBException)3 Path (java.nio.file.Path)2 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)2 Graph (org.apache.jena.graph.Graph)2 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)2 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Timer (org.apache.jena.atlas.lib.Timer)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 CmdException (org.apache.jena.cmd.CmdException)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1