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