Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void clearStorage() throws BackendException {
if (keyspaceDefinition == null) {
return;
}
for (final ColumnFamilyDefinition cf : cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
for (final ColumnFamilyDefinition cf : keyspaceDefinition.getColumnFamilyList()) {
ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws Back

}

private class FilterDeletedColumns implements Predicate<Cell> {
private static class FilterDeletedColumns implements Predicate<Cell> {

private final long tsMillis;
private final int tsSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ public Map<StaticBuffer, EntryList> getNamesSlice(List<StaticBuffer> keys,
*/
Map<StaticBuffer, EntryList> results = new HashMap<StaticBuffer, EntryList>();

for (ByteBuffer key : rows.keySet()) {
results.put(StaticArrayBuffer.of(key),
CassandraHelper.makeEntryList(rows.get(key), entryGetter, query.getSliceEnd(), query.getLimit()));
for (final Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> entry : rows.entrySet()) {
results.put(StaticArrayBuffer.of(entry.getKey()),
CassandraHelper.makeEntryList(entry.getValue(), entryGetter, query.getSliceEnd(), query.getLimit()));
}

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.janusgraph.util.system.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -125,7 +126,12 @@ public static void drop(JanusGraph graph) throws BackendException {
graph.close();
}
final GraphDatabaseConfiguration config = g.getConfiguration();
config.getBackend().clearStorage();
final Backend backend = config.getBackend();
try {
backend.clearStorage();
} finally {
IOUtils.closeQuietly(backend);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import com.google.common.base.Preconditions;
import org.janusgraph.core.JanusGraph;

import org.janusgraph.diskstorage.Backend;
import org.janusgraph.diskstorage.util.BackendOperation;
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
import org.janusgraph.graphdb.database.StandardJanusGraph;
import org.janusgraph.util.system.IOUtils;

import java.time.Duration;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -50,7 +52,12 @@ public static final void clear(JanusGraph graph) {
BackendOperation.execute(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
config.getBackend().clearStorage();
final Backend backend = config.getBackend();
try {
backend.clearStorage();
} finally {
IOUtils.closeQuietly(backend);
}
return true;
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.time.Duration;

import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID;
import static org.janusgraph.util.encoding.StringEncoding.UTF8_CHARSET;


/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class AbstractIDAuthority implements IDAuthority {
public AbstractIDAuthority(Configuration config) {
this.uid = config.get(UNIQUE_INSTANCE_ID);

this.uidBytes = uid.getBytes();
this.uidBytes = uid.getBytes(UTF8_CHARSET);

this.isActive = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void resetDelete() {
@Nullable
@Override
public String apply(@Nullable IndexEntry indexEntry) {
Preconditions.checkNotNull(indexEntry);
return indexEntry.field;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.janusgraph.diskstorage.keycolumnvalue.cache;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import org.janusgraph.diskstorage.Entry;
import org.janusgraph.diskstorage.Mutation;
import org.janusgraph.diskstorage.StaticBuffer;
Expand All @@ -35,6 +36,7 @@ public KCVEntryMutation(List<Entry> additions, List<Entry> deletions) {
@Nullable
@Override
public StaticBuffer apply(@Nullable Entry entry) {
Preconditions.checkNotNull(entry);
return entry.getColumn();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, Pe
// interrupt
boolean ok = false;
try {
for (KeyColumn kc : m.keySet()) {
checkSingleLock(kc, m.get(kc), tx);
for (final Map.Entry<KeyColumn, S> entry : m.entrySet()) {
checkSingleLock(entry.getKey(), entry.getValue(), tx);
}
ok = true;
} catch (TemporaryLockingException tle) {
Expand Down Expand Up @@ -378,10 +378,11 @@ public void deleteLocks(StoreTransaction tx) throws TemporaryLockingException, P

Map<KeyColumn, S> m = lockState.getLocksForTx(tx);

Iterator<KeyColumn> iter = m.keySet().iterator();
final Iterator<Map.Entry<KeyColumn, S>> iter = m.entrySet().iterator();
while (iter.hasNext()) {
KeyColumn kc = iter.next();
S ls = m.get(kc);
final Map.Entry<KeyColumn, S> entry = iter.next();
final KeyColumn kc = entry.getKey();
final S ls = entry.getValue();
try {
deleteSingleLock(kc, ls, tx);
} catch (AssertionError ae) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.Arrays;
import java.util.List;

import static org.janusgraph.util.encoding.StringEncoding.UTF8_CHARSET;

/**
* A global {@link Locker} that resolves inter-thread lock contention via
* {@link AbstractLocker} and resolves inter-process contention by reading and
Expand Down Expand Up @@ -224,7 +226,7 @@ public Builder customCleaner(LockCleanerService s) {
}

public Builder fromConfig(Configuration config) {
rid(new StaticArrayBuffer(config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID).getBytes()));
rid(new StaticArrayBuffer(config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID).getBytes(UTF8_CHARSET)));

final String llmPrefix = config.get(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public Iterable<Object[]> getRecordValues() {
@Nullable
@Override
public Object[] apply(@Nullable RecordEntry[] record) {
Preconditions.checkNotNull(record);
return getValues(record);
}
});
Expand Down Expand Up @@ -563,7 +564,7 @@ public IndexQuery getQuery(final MixedIndexType index, final Condition condition
@Nullable
@Override
public Condition<JanusGraphElement> apply(@Nullable Condition<JanusGraphElement> condition) {
Preconditions.checkArgument(condition instanceof PredicateCondition);
Preconditions.checkArgument(condition != null && condition instanceof PredicateCondition);
PredicateCondition pc = (PredicateCondition) condition;
PropertyKey key = (PropertyKey) pc.getKey();
return new PredicateCondition<String, JanusGraphElement>(key2Field(index,key), pc.getPredicate(), pc.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ public ModificationSummary prepareCommit(final Collection<InternalRelation> adde
private static final Predicate<InternalRelation> SCHEMA_FILTER = new Predicate<InternalRelation>() {
@Override
public boolean apply(@Nullable InternalRelation internalRelation) {
Preconditions.checkNotNull(internalRelation);
return internalRelation.getType() instanceof BaseRelationType && internalRelation.getVertex(0) instanceof JanusGraphSchemaVertex;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public boolean equals(Object other) {
return getCompareId()==((AbstractElement)other).getCompareId();
} else if (other instanceof JanusGraphElement) {
return ((JanusGraphElement) other).hasId() && getCompareId()==((JanusGraphElement)other).longId();
} else if (other instanceof Element) {
} else {
Object otherId = ((Element)other).id();
if (otherId instanceof RelationIdentifier) return ((RelationIdentifier) otherId).getRelationId()==getCompareId();
else return otherId.equals(getCompareId());
} else return false;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public Future<ComputerResult> submit() {
@Nullable
@Override
public Map<String, Object> apply(@Nullable Map<String, Object> o) {
Preconditions.checkNotNull(o);
return Maps.filterKeys(o, s -> !VertexProgramHelper.isTransientVertexComputeKey(s, vertexProgram.getVertexComputeKeys()));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.janusgraph.graphdb.query.condition;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import org.janusgraph.core.JanusGraphElement;

Expand All @@ -32,6 +33,7 @@ public static final<E extends JanusGraphElement> Condition<E> literalTransformat
@Nullable
@Override
public Condition<E> apply(@Nullable Condition<E> cond) {
Preconditions.checkNotNull(cond);
if (cond.getType()== Condition.Type.LITERAL) return transformation.apply(cond);
else return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void foldInOrder(final HasStepFolder janusgraphStep, final Traversal.Admi
currentStep = currentStep.getNextStep();
}

if (lastOrder != null && lastOrder instanceof OrderGlobalStep) {
if (lastOrder != null) {
if (validJanusGraphOrder(lastOrder, rootTraversal, isVertexOrder)) {
//Add orders to HasStepFolder
for (Pair<Traversal.Admin<Object, Comparable>, Comparator<Comparable>> comp : (List<Pair<Traversal.Admin<Object, Comparable>, Comparator<Comparable>>>) ((OrderGlobalStep) lastOrder).getComparators()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ public Iterator<JanusGraphRelation> getNew(final VertexCentricQuery query) {

@Override
public boolean apply(@Nullable InternalRelation relation) {
Preconditions.checkNotNull(relation);
if ((relation instanceof JanusGraphEdge) && relation.isLoop()
&& query.getDirection() != Direction.BOTH) {
if (relation.equals(previous))
Expand Down Expand Up @@ -1179,6 +1180,7 @@ public Iterator<JanusGraphElement> getNew(final GraphCentricQuery query) {
ConditionUtil.traversal(query.getCondition(), new Predicate<Condition<JanusGraphElement>>() {
@Override
public boolean apply(@Nullable Condition<JanusGraphElement> cond) {
Preconditions.checkNotNull(cond);
Preconditions.checkArgument(cond.getType() != Condition.Type.LITERAL || cond instanceof PredicateCondition);
if (cond instanceof PredicateCondition)
keys.add(((PredicateCondition<PropertyKey, JanusGraphElement>) cond).getKey());
Expand All @@ -1190,6 +1192,7 @@ public boolean apply(@Nullable Condition<JanusGraphElement> cond) {
for (JanusGraphRelation r : addedRelations.getView(new Predicate<InternalRelation>() {
@Override
public boolean apply(@Nullable InternalRelation relation) {
Preconditions.checkNotNull(relation);
return keys.contains(relation.getType());
}
})) {
Expand All @@ -1207,6 +1210,7 @@ public boolean apply(@Nullable InternalRelation relation) {
@Nullable
@Override
public JanusGraphVertex apply(@Nullable JanusGraphVertexProperty o) {
Preconditions.checkNotNull(o);
return o.element();
}
});
Expand All @@ -1223,6 +1227,7 @@ public boolean apply(@Nullable JanusGraphVertex vertex) {
return (Iterator) addedRelations.getView(new Predicate<InternalRelation>() {
@Override
public boolean apply(@Nullable InternalRelation relation) {
Preconditions.checkNotNull(relation);
return query.getResultType().isInstance(relation) && !relation.isInvisible() && query.matches(relation);
}
}).iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.janusgraph.graphdb.util;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.janusgraph.core.*;
Expand Down Expand Up @@ -42,6 +43,7 @@ public static Iterable<Object> getValues(JanusGraphElement element, PropertyKey
@Nullable
@Override
public Object apply(@Nullable JanusGraphVertexProperty janusgraphProperty) {
Preconditions.checkNotNull(janusgraphProperty);
return janusgraphProperty.value();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
public class WorkerPool implements AutoCloseable {

private final ThreadPoolExecutor processor;
private final long shutdownWaitMS = 10000;
private static final long SHUTDOWN_WAIT_MS = 10000;

private final ThreadPoolExecutor processor;

public WorkerPool(int numThreads) {
processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(128));
Expand All @@ -41,7 +41,7 @@ public void submit(Runnable runnable) {
@Override
public void close() throws Exception {
processor.shutdown();
processor.awaitTermination(shutdownWaitMS,TimeUnit.MILLISECONDS);
processor.awaitTermination(SHUTDOWN_WAIT_MS,TimeUnit.MILLISECONDS);
if (!processor.isTerminated()) {
//log.error("Processor did not terminate in time");
processor.shutdownNow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@

import com.google.common.base.Preconditions;

import java.nio.charset.Charset;

/**
* @author Matthias Broecheler (me@matthiasb.com)
*/
public class StringEncoding {

public static final String UTF8_ENCODING = "UTF-8";

public static final Charset UTF8_CHARSET = Charset.forName(UTF8_ENCODING);

public static boolean isAsciiString(String input) {
Preconditions.checkNotNull(input);
for (int i = 0; i < input.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package org.janusgraph.util.system;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -31,6 +31,8 @@
import org.janusgraph.diskstorage.configuration.ConfigNamespace;
import org.janusgraph.diskstorage.configuration.ConfigOption;

import static org.janusgraph.util.encoding.StringEncoding.UTF8_ENCODING;

/**
* Recursively dump the root configuration namespace to either System.out or the
* named file in a CSV-type format with configurable delimiter, header, and
Expand All @@ -49,8 +51,7 @@ public class ConfigurationPrinter {
private final boolean showMutability;
private final PrintStream stream;

public static void main(String args[]) throws FileNotFoundException, IllegalAccessException,
NoSuchFieldException, ClassNotFoundException {
public static void main(String args[]) throws IOException, ReflectiveOperationException {

ReflectiveConfigOptionLoader.INSTANCE.loadStandard(ConfigurationPrinter.class);

Expand All @@ -62,7 +63,7 @@ public static void main(String args[]) throws FileNotFoundException, IllegalAcce
}

final ConfigNamespace root = stringToNamespace(args[0]);
final PrintStream stream = new PrintStream(new FileOutputStream(args[1]));
final PrintStream stream = new PrintStream(new FileOutputStream(args[1]), false, UTF8_ENCODING);
final boolean mutability = Boolean.valueOf(args[2]);

new ConfigurationPrinter(stream, mutability).write(root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void register(String store, String key, KeyInformation information, BaseT
try {
//We check if the externalMapping have the property 'key'
final Map mappings = client.getMapping(indexStoreName, store);
if (!mappings.containsKey(key)) {
if (mappings == null || !mappings.containsKey(key)) {
throw new PermanentBackendException("The external mapping for index '"+ indexStoreName +"' and type '"+store+"' do not have property '"+key+"'");
}
} catch (final IOException e) {
Expand Down Expand Up @@ -711,7 +711,6 @@ public Map<String,Object> getFilter(Condition<?> condition, KeyInformation.Store
if (value instanceof Number) {
Preconditions.checkArgument(janusgraphPredicate instanceof Cmp, "Relation not supported on numeric types: " + janusgraphPredicate);
final Cmp numRel = (Cmp) janusgraphPredicate;
Preconditions.checkArgument(value instanceof Number);

switch (numRel) {
case EQUAL:
Expand Down
Loading