/** obsolete every file in the original transaction */ public void obsoleteOriginals() { logger.debug("Staging for obsolescence {}", originals); // if we're obsoleting, we should have no staged updates for the original files assert Iterables.isEmpty(filterIn(staged.update, originals)) : staged.update; // stage obsoletes for any currently visible versions of any original readers Iterables.addAll(staged.obsolete, filterIn(current(), originals)); }
private String getNameFor(final String key) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); return parts[parts.length - 1]; }
@Override public TitanType getType(String name) { verifyOpen(); TitanType type = typeCache.get(name); if (type == null) type = (TitanType) Iterables.getOnlyElement(getVertices(SystemKey.TypeName, name), null); return type; }
/** * @param sstables * @return */ public static List<Pair<SSTableReader, Long>> createSSTableAndMinTimestampPairs( Iterable<SSTableReader> sstables) { List<Pair<SSTableReader, Long>> sstableMinTimestampPairs = Lists.newArrayListWithCapacity(Iterables.size(sstables)); for (SSTableReader sstable : sstables) sstableMinTimestampPairs.add(Pair.create(sstable, sstable.getMinTimestamp())); return sstableMinTimestampPairs; }
@Override public TitanEdge addEdge(TitanVertex outVertex, TitanVertex inVertex, TitanLabel label) { verifyWriteAccess(outVertex, inVertex); outVertex = ((InternalVertex) outVertex).it(); inVertex = ((InternalVertex) inVertex).it(); Preconditions.checkNotNull(label); Lock uniqueLock = FakeLock.INSTANCE; if (config.hasVerifyUniqueness() && (label.isUnique(Direction.OUT) || label.isUnique(Direction.IN))) uniqueLock = getUniquenessLock(outVertex, label, inVertex); uniqueLock.lock(); try { // Check uniqueness if (config.hasVerifyUniqueness()) { if (label.isUnique(Direction.OUT)) { Preconditions.checkArgument( Iterables.isEmpty( query(outVertex) .includeHidden() .type(label) .direction(Direction.OUT) .titanEdges()), "An edge with the given type already exists on the out-vertex"); } if (label.isUnique(Direction.IN)) { Preconditions.checkArgument( Iterables.isEmpty( query(inVertex).includeHidden().type(label).direction(Direction.IN).titanEdges()), "An edge with the given type already exists on the in-vertex"); } } StandardEdge edge = new StandardEdge( temporaryID.decrementAndGet(), label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New); if (config.hasAssignIDsImmediately()) graph.assignID(edge); connectRelation(edge); return edge; } finally { uniqueLock.unlock(); } }
@Override public void removeKey(final String key) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); final Map<String, Tag> parent = this.findLastParent(parts); parent.remove(parts[parts.length - 1]); }
private void declareClass( ClassVisitor visitor, Collection<String> interfaceInternalNames, Type generatedType, Type superclassType) { visitor.visit( V1_6, ACC_PUBLIC, generatedType.getInternalName(), null, superclassType.getInternalName(), Iterables.toArray(interfaceInternalNames, String.class)); }
@Override public Iterable<Vertex> getVertices() { if (!addedRelations.isEmpty()) { // There are possible new vertices List<Vertex> newVs = new ArrayList<Vertex>(); for (InternalVertex v : vertexCache.getAll()) { if (v.isNew() && !(v instanceof TitanType)) newVs.add(v); } return Iterables.concat(newVs, new VertexIterable(graph, this)); } else { return (Iterable) new VertexIterable(graph, this); } }
public TitanProperty addPropertyInternal(TitanVertex vertex, TitanKey key, Object value) { verifyWriteAccess(vertex); vertex = ((InternalVertex) vertex).it(); Preconditions.checkNotNull(key); value = AttributeUtil.verifyAttribute(key, value); Lock uniqueLock = FakeLock.INSTANCE; if (config.hasVerifyUniqueness() && (key.isUnique(Direction.OUT) || key.isUnique(Direction.IN))) uniqueLock = getUniquenessLock(vertex, key, value); uniqueLock.lock(); try { // Check uniqueness if (config.hasVerifyUniqueness()) { if (key.isUnique(Direction.OUT)) { Preconditions.checkArgument( Iterables.isEmpty( query(vertex).includeHidden().type(key).direction(Direction.OUT).properties()), "An property with the given key already exists on the vertex and the property key is defined as out-unique"); } if (key.isUnique(Direction.IN)) { Preconditions.checkArgument( Iterables.isEmpty(getVertices(key, value)), "The given value is already used as a property and the property key is defined as in-unique"); } } StandardProperty prop = new StandardProperty( temporaryID.decrementAndGet(), key, (InternalVertex) vertex, value, ElementLifeCycle.New); if (config.hasAssignIDsImmediately()) graph.assignID(prop); connectRelation(prop); return prop; } finally { uniqueLock.unlock(); } }
/** * Removes all sstables with max timestamp older than maxSSTableAge. * * @param sstables all sstables to consider * @param maxSSTableAge the age in milliseconds when an SSTable stops participating in compactions * @param now current time. SSTables with max timestamp less than (now - maxSSTableAge) are * filtered. * @return a list of sstables with the oldest sstables excluded */ @VisibleForTesting static Iterable<SSTableReader> filterOldSSTables( List<SSTableReader> sstables, long maxSSTableAge, long now) { if (maxSSTableAge == 0) return sstables; final long cutoff = now - maxSSTableAge; return Iterables.filter( sstables, new Predicate<SSTableReader>() { @Override public boolean apply(SSTableReader sstable) { return sstable.getMaxTimestamp() >= cutoff; } }); }
private void putTag(final String key, final Tag tag) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); Map<String, Tag> parent = NBTStorage.this.root; for (int i = 0; i < parts.length - 1; ++i) { if (!parent.containsKey(parts[i]) || !(parent.get(parts[i]) instanceof CompoundTag)) { parent.put(parts[i], new CompoundTag(parts[i])); } parent = parent.get(parts[i]).getValue(); } parent.put(tag.getName(), tag); }
private RelOptTableImpl getTableFrom(List<String> names, List<String> schemaNames) { OptiqSchema schema = getSchema(Iterables.concat(schemaNames, Util.skipLast(names))); if (schema == null) { return null; } final String name = Util.last(names); Pair<String, Table> pair = schema.getTable(name, caseSensitive); if (pair == null) { pair = schema.getTableBasedOnNullaryFunction(name, caseSensitive); } if (pair != null) { final Table table = pair.getValue(); final String name2 = pair.getKey(); return RelOptTableImpl.create(this, table.getRowType(typeFactory), schema.add(name2, table)); } return null; }
private Tag findLastTag(final String key, final boolean relative) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.') .omitEmptyStrings() .split((CharSequence) (relative ? this.createRelativeKey(key) : key)), (Class) String.class); if (parts.length == 0) { return new CompoundTag(NBTStorage.this.name, NBTStorage.this.root); } final Map<String, Tag> map = this.findLastParent(parts); if (!map.containsKey(parts[parts.length - 1])) { return null; } return map.get(parts[parts.length - 1]); }
private void writeDelegateMethods( final ClassVisitor visitor, final Type generatedType, StructSchema<?> delegateSchema, Set<Class<?>> typesToDelegate) { Class<?> delegateClass = delegateSchema.getType().getConcreteClass(); Type delegateType = Type.getType(delegateClass); Map<Equivalence.Wrapper<Method>, Map<Class<?>, Method>> methodsToDelegate = Maps.newHashMap(); for (Class<?> typeToDelegate : typesToDelegate) { for (Method methodToDelegate : typeToDelegate.getMethods()) { if (ModelSchemaUtils.isIgnoredMethod(methodToDelegate)) { continue; } Equivalence.Wrapper<Method> methodKey = METHOD_EQUIVALENCE.wrap(methodToDelegate); Map<Class<?>, Method> methodsByReturnType = methodsToDelegate.get(methodKey); if (methodsByReturnType == null) { methodsByReturnType = Maps.newHashMap(); methodsToDelegate.put(methodKey, methodsByReturnType); } methodsByReturnType.put(methodToDelegate.getReturnType(), methodToDelegate); } } Set<Equivalence.Wrapper<Method>> delegateMethodKeys = ImmutableSet.copyOf( Iterables.transform( Arrays.asList(delegateClass.getMethods()), new Function<Method, Equivalence.Wrapper<Method>>() { @Override public Equivalence.Wrapper<Method> apply(Method method) { return METHOD_EQUIVALENCE.wrap(method); } })); for (Map.Entry<Equivalence.Wrapper<Method>, Map<Class<?>, Method>> entry : methodsToDelegate.entrySet()) { Equivalence.Wrapper<Method> methodKey = entry.getKey(); if (!delegateMethodKeys.contains(methodKey)) { continue; } Map<Class<?>, Method> methodsByReturnType = entry.getValue(); for (Method methodToDelegate : methodsByReturnType.values()) { writeDelegatedMethod(visitor, generatedType, delegateType, methodToDelegate); } } }
private Collection<Function> getFunctionsFrom(List<String> names) { final List<Function> functions2 = Lists.newArrayList(); final List<? extends List<String>> schemaNameList; if (names.size() > 1) { // If name is qualified, ignore path. schemaNameList = ImmutableList.of(ImmutableList.<String>of()); } else { OptiqSchema schema = getSchema(defaultSchema); if (schema == null) { schemaNameList = ImmutableList.of(); } else { schemaNameList = schema.getPath(); } } for (List<String> schemaNames : schemaNameList) { OptiqSchema schema = getSchema(Iterables.concat(schemaNames, Util.skipLast(names))); if (schema != null) { final String name = Util.last(names); functions2.addAll(schema.getFunctions(name, true)); } } return functions2; }
/** @deprecated retained for benefit of old tests */ public Collection<InetAddress> getWriteEndpoints( Token token, String keyspaceName, Collection<InetAddress> naturalEndpoints) { return ImmutableList.copyOf( Iterables.concat(naturalEndpoints, pendingEndpointsFor(token, keyspaceName))); }
@Override public TitanVertex getVertex(TitanKey key, Object attribute) { Preconditions.checkArgument( key.isUnique(Direction.IN), "Key is not uniquely associated to value [%s]", key.getName()); return Iterables.getOnlyElement(getVertices(key, attribute), null); }
@Override public Iterator<TitanRelation> execute(final VertexCentricQuery query) { if (query.getVertex().isNew()) return Iterators.emptyIterator(); final EdgeSerializer edgeSerializer = graph.getEdgeSerializer(); FittedSliceQuery sq = edgeSerializer.getQuery(query); final boolean fittedQuery = sq.isFitted(); final InternalVertex v = query.getVertex(); final boolean needsFiltering = !sq.isFitted() || !deletedRelations.isEmpty(); if (needsFiltering && sq.hasLimit()) sq = new FittedSliceQuery(sq, QueryUtil.updateLimit(sq.getLimit(), 1.1)); Iterable<TitanRelation> result = null; double limitMultiplier = 1.0; int previousDiskSize = 0; boolean finished; do { finished = true; Iterable<Entry> iter = null; if (v instanceof CacheVertex) { CacheVertex cv = (CacheVertex) v; iter = ((CacheVertex) v) .loadRelations( sq, new Retriever<SliceQuery, List<Entry>>() { @Override public List<Entry> get(SliceQuery query) { return graph.edgeQuery(v.getID(), query, txHandle); } }); } else { iter = graph.edgeQuery(v.getID(), sq, txHandle); } result = Iterables.transform( iter, new Function<Entry, TitanRelation>() { @Nullable @Override public TitanRelation apply(@Nullable Entry entry) { return edgeSerializer.readRelation(v, entry); } }); if (needsFiltering) { result = Iterables.filter( result, new Predicate<TitanRelation>() { @Override public boolean apply(@Nullable TitanRelation relation) { // Filter out updated and deleted relations return (relation == ((InternalRelation) relation).it() && !deletedRelations.containsKey(Long.valueOf(relation.getID()))) && (fittedQuery || query.matches(relation)); } }); } // Determine termination if (needsFiltering && query.hasLimit()) { if (!IterablesUtil.sizeLargerOrEqualThan(result, query.getLimit())) { int currentDiskSize = IterablesUtil.size(iter); if (currentDiskSize > previousDiskSize) { finished = false; previousDiskSize = currentDiskSize; limitMultiplier *= 2; sq = new FittedSliceQuery( sq, QueryUtil.updateLimit(sq.getLimit(), limitMultiplier)); } } } } while (!finished); return result.iterator(); }
@Override public boolean containsType(String name) { verifyOpen(); return (typeCache.containsKey(name) || !Iterables.isEmpty(getVertices(SystemKey.TypeName, name))); }