private <N extends InternalTitanVertex> void persist( ListMultimap<N, InternalRelation> mutatedEdges, Map<TitanType, TypeSignature> signatures, InternalTitanTransaction tx, StoreMutator mutator) throws StorageException { assert mutatedEdges != null && !mutatedEdges.isEmpty(); Collection<N> vertices = mutatedEdges.keySet(); // if (sortNodes) { // List<N> sortedvertices = new ArrayList<N>(vertices); // Collections.sort(sortedvertices, new Comparator<N>(){ // // @Override // public int compare(N o1, N o2) { // assert o1.getID()!=o2.getID(); // if (o1.getID()<o2.getID()) return -1; // else return 1; // } // // }); // vertices=sortedvertices; // } for (N node : vertices) { List<InternalRelation> edges = mutatedEdges.get(node); List<Entry> additions = new ArrayList<Entry>(edges.size()); List<ByteBuffer> deletions = new ArrayList<ByteBuffer>(Math.max(10, edges.size() / 10)); List<TitanProperty> properties = new ArrayList<TitanProperty>(); for (InternalRelation edge : edges) { if (edge.isRemoved()) { if (edge.isProperty()) { deleteIndexEntry((TitanProperty) edge, mutator); } deletions.add(getEntry(tx, edge, node, signatures, true).getColumn()); } else { assert edge.isNew(); if (edge.isProperty()) properties.add((TitanProperty) edge); additions.add(getEntry(tx, edge, node, signatures)); } } mutator.mutateEdges(IDHandler.getKey(node.getID()), additions, deletions); // Persist property index for retrieval for (TitanProperty prop : properties) { addIndexEntry(prop, mutator); } } }
private List<Entry> appendResults( ByteBuffer key, ByteBuffer columnStart, ByteBuffer columnEnd, List<Entry> entries, LimitTracker limit, TransactionHandle txh) { if (limit.limitExhausted()) return null; List<Entry> results = null; for (int readAttempt = 0; readAttempt < maxReadRetryAttempts; readAttempt++) { try { results = edgeStore.getSlice(key, columnStart, columnEnd, limit.getLimit(), txh); break; } catch (StorageException e) { if (e instanceof TemporaryStorageException) { if (readAttempt < maxReadRetryAttempts - 1) temporaryStorageException(e); else throw readException(e, maxReadRetryAttempts); } else throw readException(e); } } limit.retrieved(results.size()); if (entries == null) return results; else { entries.addAll(results); return entries; } }
@Override public long[] indexRetrieval(Object key, TitanKey pt, InternalTitanTransaction tx) { Preconditions.checkArgument( pt.isSimple(), "Currently, only simple properties are supported for index retrieval"); Preconditions.checkArgument( pt.hasIndex(), "Cannot retrieve for given property key - it does not have an index"); long[] vertices = null; Preconditions.checkArgument( pt.getDataType().isInstance(key), "Specified object is incompatible with property data type [" + pt.getName() + "]"); for (int readAttempt = 0; readAttempt < maxReadRetryAttempts; readAttempt++) { try { if (pt.isUnique()) { ByteBuffer value = propertyIndex.get(getIndexKey(key), getKeyedIndexColumn(pt), tx.getTxHandle()); if (value != null) { vertices = new long[1]; vertices[0] = VariableLong.readPositive(value); } } else { ByteBuffer startColumn = VariableLong.positiveByteBuffer(pt.getID()); List<Entry> entries = propertyIndex.getSlice( getIndexKey(key), startColumn, ByteBufferUtil.nextBiggerBuffer(startColumn), tx.getTxHandle()); vertices = new long[entries.size()]; int i = 0; for (Entry ent : entries) { vertices[i++] = VariableLong.readPositive(ent.getValue()); } } break; } catch (StorageException e) { if (e instanceof TemporaryStorageException) { if (readAttempt < maxReadRetryAttempts - 1) temporaryStorageException(e); else throw readException(e, maxReadRetryAttempts); } else throw readException(e); } } if (vertices == null) return new long[0]; else return vertices; }