use of com.thinkaurelius.titan.diskstorage.EntryList in project titan by thinkaurelius.
the class IndexRemoveJob method process.
@Override
public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) {
//The queries are already tailored enough => everything should be removed
try {
BackendTransaction mutator = writeTx.getTxHandle();
final List<Entry> deletions;
if (entries.size() == 1)
deletions = Iterables.getOnlyElement(entries.values());
else {
int size = IteratorUtils.stream(entries.values().iterator()).map(e -> e.size()).reduce(0, (x, y) -> x + y);
deletions = new ArrayList<>(size);
entries.values().forEach(e -> deletions.addAll(e));
}
metrics.incrementCustom(DELETED_RECORDS_COUNT, deletions.size());
if (isRelationTypeIndex()) {
mutator.mutateEdges(key, KCVSCache.NO_ADDITIONS, deletions);
} else {
mutator.mutateIndex(key, KCVSCache.NO_ADDITIONS, deletions);
}
} catch (final Exception e) {
mgmt.rollback();
writeTx.rollback();
metrics.incrementCustom(FAILED_TX);
throw new TitanException(e.getMessage(), e);
}
}
use of com.thinkaurelius.titan.diskstorage.EntryList in project titan by thinkaurelius.
the class StandardSchemaCache method getSchemaRelations.
@Override
public EntryList getSchemaRelations(final long schemaId, final BaseRelationType type, final Direction dir) {
assert IDManager.isSystemRelationTypeId(type.longId()) && type.longId() > 0;
Preconditions.checkArgument(IDManager.VertexIDType.Schema.is(schemaId));
Preconditions.checkArgument((Long.MAX_VALUE >>> (SCHEMAID_TOTALFORW_SHIFT - SCHEMAID_BACK_SHIFT)) >= schemaId);
int edgeDir = EdgeDirection.position(dir);
assert edgeDir == 0 || edgeDir == 1;
final long typePlusRelation = getIdentifier(schemaId, type, dir);
ConcurrentMap<Long, EntryList> types = schemaRelations;
EntryList entries;
if (types == null) {
entries = schemaRelationsBackup.getIfPresent(typePlusRelation);
if (entries == null) {
entries = retriever.retrieveSchemaRelations(schemaId, type, dir);
if (!entries.isEmpty()) {
//only cache if type exists
schemaRelationsBackup.put(typePlusRelation, entries);
}
}
} else {
entries = types.get(typePlusRelation);
if (entries == null) {
//Retrieve it
if (types.size() > maxCachedRelations) {
/* Safe guard against the concurrent hash map growing to large - this would be a VERY rare event
as it only happens for graph databases with thousands of types.
*/
schemaRelations = null;
return getSchemaRelations(schemaId, type, dir);
} else {
//Expand map
entries = retriever.retrieveSchemaRelations(schemaId, type, dir);
types.put(typePlusRelation, entries);
}
}
}
assert entries != null;
return entries;
}
use of com.thinkaurelius.titan.diskstorage.EntryList in project titan by thinkaurelius.
the class StandardTitanTx method getVertices.
@Override
public Iterable<TitanVertex> getVertices(long... ids) {
verifyOpen();
if (ids == null || ids.length == 0)
return (Iterable) getInternalVertices();
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "db", "getVerticesByID").inc();
}
List<TitanVertex> result = new ArrayList<TitanVertex>(ids.length);
LongArrayList vids = new LongArrayList(ids.length);
for (long id : ids) {
if (isValidVertexId(id)) {
if (idInspector.isPartitionedVertex(id))
id = idManager.getCanonicalVertexId(id);
if (vertexCache.contains(id))
result.add(vertexCache.get(id, existingVertexRetriever));
else
vids.add(id);
}
}
if (!vids.isEmpty()) {
if (externalVertexRetriever.hasVerifyExistence()) {
List<EntryList> existence = graph.edgeMultiQuery(vids, graph.vertexExistenceQuery, txHandle);
for (int i = 0; i < vids.size(); i++) {
if (!existence.get(i).isEmpty()) {
long id = vids.get(i);
result.add(vertexCache.get(id, existingVertexRetriever));
}
}
} else {
for (int i = 0; i < vids.size(); i++) {
result.add(vertexCache.get(vids.get(i), externalVertexRetriever));
}
}
}
//Filter out potentially removed vertices
for (Iterator<TitanVertex> iterator = result.iterator(); iterator.hasNext(); ) {
if (iterator.next().isRemoved())
iterator.remove();
}
return result;
}
use of com.thinkaurelius.titan.diskstorage.EntryList in project titan by thinkaurelius.
the class HadoopScanMapper method map.
@Override
protected void map(StaticBuffer key, Iterable<Entry> values, Context context) throws IOException, InterruptedException {
EntryArrayList al = EntryArrayList.of(values);
// KeyFilter check
if (!keyFilter.test(key)) {
log.debug("Skipping key {} based on KeyFilter", key);
return;
}
// InitialQuery check (at least one match is required or else the key is ignored)
EntryList initialQueryMatches = findEntriesMatchingQuery(initialQuery, al);
if (0 == initialQueryMatches.size()) {
log.debug("Skipping key {} based on InitialQuery ({}) match failure", key, initialQuery);
return;
}
// Both conditions (KeyFilter && InitialQuery) for invoking process are satisfied
// Create an entries parameter to be passed into the process method
Map<SliceQuery, EntryList> matches = new HashMap<>();
matches.put(initialQuery, initialQueryMatches);
// Find matches (if any are present) for noninitial queries
for (SliceQuery sq : subsequentQueries) {
matches.put(sq, findEntriesMatchingQuery(sq, al));
}
// Process
job.process(key, matches, metrics);
}
use of com.thinkaurelius.titan.diskstorage.EntryList in project titan by thinkaurelius.
the class StandardTitanTx method executeMultiQuery.
public void executeMultiQuery(final Collection<InternalVertex> vertices, final SliceQuery sq, final QueryProfiler profiler) {
LongArrayList vids = new LongArrayList(vertices.size());
for (InternalVertex v : vertices) {
if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq))
vids.add(v.longId());
}
if (!vids.isEmpty()) {
List<EntryList> results = QueryProfiler.profile(profiler, sq, true, q -> graph.edgeMultiQuery(vids, q, txHandle));
int pos = 0;
for (TitanVertex v : vertices) {
if (pos < vids.size() && vids.get(pos) == v.longId()) {
final EntryList vresults = results.get(pos);
((CacheVertex) v).loadRelations(sq, new Retriever<SliceQuery, EntryList>() {
@Override
public EntryList get(SliceQuery query) {
return vresults;
}
});
pos++;
}
}
}
}
Aggregations