@Override public String getName() { return index.getName() ; }
/** Choose an index to scan in case we are asked for everything * This needs to be ???G for the distinctAdjacent filter in union query to work. */ private static TupleIndex chooseScanAllIndex(int tupleLen, TupleIndex[] indexes) { if ( tupleLen != 4 ) return indexes[0] ; for ( TupleIndex index : indexes ) { // First look for SPOG if ( index.getName().equals("SPOG") ) return index ; } for ( TupleIndex index : indexes ) { // Then look for any ???G if ( index.getName().endsWith("G") ) return index ; } Log.warn(SystemTDB.errlog, "Did not find a ???G index for full scans") ; return indexes[0] ; }
static Map<String, TupleIndex> indexMap(DatasetGraphTDB dsgtdb) { Map<String, TupleIndex> indexMap = new HashMap<>(); // All triple/quad indexes. Arrays.stream(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes()) .forEach(idx->indexMap.put(idx.getName(), idx)); Arrays.stream(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes()) .forEach(idx->indexMap.put(idx.getName(), idx)); return indexMap; }
/** Execute secondary index building of a {@link LoaderPlan} */ private static void executeSecondary(TupleIndex srcIdx, TupleIndex[][] indexSets, DatasetGraphTDB dsgtdb, MonitorOutput output) { if ( indexSets.length == 0 ) return; List<BulkStartFinish> processes = new ArrayList<>(); output.print("Start replay index %s", srcIdx.getName()); // For each phase. for ( TupleIndex[] indexes : indexSets ) { if ( indexes.length == 0 ) // Nothing in this phase. continue; indexPhase(processes, srcIdx, indexes, output); // processes - wait now or wait later? } // Now make sure they are flushed. BulkProcesses.finish(processes); }
public static void createSecondaryIndexes(MonitorOutput output, TupleIndex primaryIndex, TupleIndex[] secondaryIndexes) { boolean printTiming = true; for ( TupleIndex index : secondaryIndexes ) { String msg = primaryIndex.getName()+"->"+index.getName(); if ( index != null ) { ProgressMonitor monitor = ProgressMonitorOutput.create(output, msg, LoaderSequential.IndexTickPoint, LoaderSequential.IndexSuperTick); monitor.startMessage(msg); monitor.start(); LoaderOps.copyIndex(primaryIndex.all(), new TupleIndex[]{index}, monitor) ; monitor.finish(); monitor.finishMessage(index.getName()+" indexing: "); } } } }
private static void indexPhase(List<BulkStartFinish> processes, TupleIndex srcIdx, TupleIndex[] indexes, MonitorOutput output) { String indexSetLabel = PhasedOps.indexMappings(indexes); output.print("Index set: %s => %s", srcIdx.getName(), indexSetLabel); Indexer indexer = new Indexer(output, indexes); Destination<Tuple<NodeId>> dest = indexer.index(); indexer.startBulk(); TransactionCoordinator coordinator = CoLib.newCoordinator(); CoLib.add(coordinator, srcIdx); CoLib.start(coordinator); // READ transaction. Transaction transaction = coordinator.begin(TxnType.READ); // Add to processes - we can wait later if we do not touched indexes being built. processes.add(indexer); PhasedOps.ReplayResult result = PhasedOps.replay(srcIdx, dest, output); // End read transaction on srcIdx transaction.end(); String timeStr = "---"; if ( result.elapsed != 0 ) { double time = result.elapsed / 1000.0; //long AvgRate = (result.items * 1000L) / result.elapsed; timeStr = String.format("%,.1f", time); } output.print("Index set: %s => %s [%,d items, %s seconds]", srcIdx.getName(), indexSetLabel, result.items, timeStr); }
private void stageIndex(BlockingQueue<List<Tuple<NodeId>>> pipe, TupleIndex idx) { TransactionCoordinator coordinator = CoLib.newCoordinator(); CoLib.add(coordinator, idx); CoLib.start(coordinator); Transaction transaction = coordinator.begin(TxnType.WRITE); boolean workHasBeenDone; try { Destination<Tuple<NodeId>> loader = loadTuples(idx); for (;;) { List<Tuple<NodeId>> tuples = pipe.take(); if ( tuples.isEmpty() ) break; loader.deliver(tuples); } workHasBeenDone = ! idx.isEmpty(); transaction.commit(); } catch (Exception ex) { ex.printStackTrace(); transaction.abort(); workHasBeenDone = false; } CoLib.finish(coordinator); if ( workHasBeenDone ) output.print("Finish - index %s", idx.getName()); termination.release(); }