Search in sources :

Example 11 with EntryList

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);
    }
}
Also used : VertexJobConverter(com.thinkaurelius.titan.graphdb.olap.VertexJobConverter) Configuration(com.thinkaurelius.titan.diskstorage.configuration.Configuration) Iterables(com.google.common.collect.Iterables) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) Entry(com.thinkaurelius.titan.diskstorage.Entry) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) IndexSerializer(com.thinkaurelius.titan.graphdb.database.IndexSerializer) ScanJob(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanJob) SchemaStatus(com.thinkaurelius.titan.core.schema.SchemaStatus) QueryContainer(com.thinkaurelius.titan.graphdb.olap.QueryContainer) TitanException(com.thinkaurelius.titan.core.TitanException) ManagementSystem(com.thinkaurelius.titan.graphdb.database.management.ManagementSystem) ArrayList(java.util.ArrayList) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) ImmutableList(com.google.common.collect.ImmutableList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) IDManager(com.thinkaurelius.titan.graphdb.idmanagement.IDManager) Map(java.util.Map) KCVSCache(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVSCache) IteratorUtils(org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) RelationTypeIndexWrapper(com.thinkaurelius.titan.graphdb.database.management.RelationTypeIndexWrapper) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) BackendTransaction(com.thinkaurelius.titan.diskstorage.BackendTransaction) ConfigOption(com.thinkaurelius.titan.diskstorage.configuration.ConfigOption) Predicate(java.util.function.Predicate) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration) ConfigElement(com.thinkaurelius.titan.diskstorage.configuration.ConfigElement) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) BufferUtil(com.thinkaurelius.titan.diskstorage.util.BufferUtil) Preconditions(com.google.common.base.Preconditions) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TitanGraph(com.thinkaurelius.titan.core.TitanGraph) Entry(com.thinkaurelius.titan.diskstorage.Entry) TitanException(com.thinkaurelius.titan.core.TitanException) BackendTransaction(com.thinkaurelius.titan.diskstorage.BackendTransaction) TitanException(com.thinkaurelius.titan.core.TitanException)

Example 12 with EntryList

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;
}
Also used : NonBlockingHashMapLong(org.cliffc.high_scale_lib.NonBlockingHashMapLong) EntryList(com.thinkaurelius.titan.diskstorage.EntryList)

Example 13 with EntryList

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;
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList) LongArrayList(com.carrotsearch.hppc.LongArrayList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList)

Example 14 with EntryList

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);
}
Also used : EntryArrayList(com.thinkaurelius.titan.diskstorage.util.EntryArrayList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 15 with EntryList

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++;
            }
        }
    }
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Aggregations

EntryList (com.thinkaurelius.titan.diskstorage.EntryList)16 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Entry (com.thinkaurelius.titan.diskstorage.Entry)5 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)4 Map (java.util.Map)4 StandardLockCleanerRunnable (com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable)3 Test (org.junit.Test)3 LongArrayList (com.carrotsearch.hppc.LongArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)2 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)2 CacheTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction)2 StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)2 CacheVertex (com.thinkaurelius.titan.graphdb.vertices.CacheVertex)2 PreloadedVertex (com.thinkaurelius.titan.graphdb.vertices.PreloadedVertex)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Preconditions (com.google.common.base.Preconditions)1 Iterables (com.google.common.collect.Iterables)1