Skip to content

Commit

Permalink
Merge pull request #2 from atlanhq/atlan-v0.6.cache
Browse files Browse the repository at this point in the history
PLT-191: support cache feature
  • Loading branch information
n5nk committed Dec 11, 2023
2 parents d88e2a4 + 1f75484 commit e7209e1
Show file tree
Hide file tree
Showing 32 changed files with 57 additions and 30 deletions.
2 changes: 1 addition & 1 deletion janusgraph-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-backend-testutils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-backend-testutils</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-berkeleyje/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-berkeleyje</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-bigtable</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public ExpirationKCVSRedisCache(final KeyColumnValueStore store, String metricsN
redisCache = redissonClient.getMapCache(String.join("-", configuration.get(CACHE_KEYSPACE_PREFIX), metricsName));
redisIndexKeys = redissonClient.getMapCache(String.join("-", configuration.get(CACHE_KEYSPACE_PREFIX), REDIS_INDEX_CACHE_PREFIX, metricsName));
redisCache.setMaxSize(configuration.get(REDIS_MAX_CACHE_SIZE), EvictionMode.LFU);
redisIndexKeys.setMaxSize(configuration.get(REDIS_MAX_CACHE_SIZE), EvictionMode.LFU);
logger.info("********************** Configurations are loaded **********************");
}

Expand All @@ -87,7 +88,7 @@ public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh)
}
}

private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) throws Exception {
byte[] bytQuery = redisCache.get(query);
EntryList entries = bytQuery != null ? (EntryList) fastConf.asObject(bytQuery) : null;
if (entries == null) {
Expand All @@ -97,23 +98,25 @@ private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
if (entries == null) {
throw new CacheLoader.InvalidCacheLoadException("valueLoader must not return null, key=" + query);
} else {
redisCache.fastPutAsync(query, fastConf.asByteArray(entries), this.cacheTimeMS,TimeUnit.MILLISECONDS);
redisCache.fastPutAsync(query, fastConf.asByteArray(entries), this.cacheTimeMS, TimeUnit.MILLISECONDS);
RLock lock = redisIndexKeys.getLock(query.getKey());
try {
lock.tryLock(1, 3, TimeUnit.SECONDS);
ArrayList<KeySliceQuery> queryList = redisIndexKeys.get(query.getKey());
if (queryList == null)
queryList = new ArrayList<>();
queryList.add(query);
redisIndexKeys.fastPutAsync(query.getKey(), queryList, this.cacheTimeMS,TimeUnit.MILLISECONDS);
redisIndexKeys.fastPutAsync(query.getKey(), queryList, this.cacheTimeMS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
throw e;
} finally {
lock.unlock();
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
return entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class KCVSCache extends KCVSProxy {

private final String metricsName;

protected String getMetricsName(){return this.metricsName;}
protected KCVSCache(KeyColumnValueStore store, String metricsName) {
super(store);
this.metricsName = metricsName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
import org.janusgraph.graphdb.tinkerpop.JanusGraphFeatures;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexFilterOptimizerStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasIdOptimizerStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasUniquePropertyOptimizerStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexIsOptimizerStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphIoRegistrationStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphLocalQueryOptimizerStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMultiQueryStrategy;
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphStepStrategy;
import org.janusgraph.graphdb.transaction.StandardJanusGraphTx;
Expand Down Expand Up @@ -485,11 +485,17 @@ public void remove() {

public EntryList edgeQuery(long vid, SliceQuery query, BackendTransaction tx) {
Preconditions.checkArgument(vid > 0);
if (!this.isCacheEnabled()) {
tx.disableCache();
}
return tx.edgeStoreQuery(new KeySliceQuery(idManager.getKey(vid), query));
}

public List<EntryList> edgeMultiQuery(LongArrayList vertexIdsAsLongs, SliceQuery query, BackendTransaction tx) {
Preconditions.checkArgument(vertexIdsAsLongs != null && !vertexIdsAsLongs.isEmpty());
if (!this.isCacheEnabled()) {
tx.disableCache();
}
final List<StaticBuffer> vertexIds = new ArrayList<>(vertexIdsAsLongs.size());
for (int i = 0; i < vertexIdsAsLongs.size(); i++) {
Preconditions.checkArgument(vertexIdsAsLongs.get(i) > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,14 @@ protected void waitCondition() throws InterruptedException {

@Override
protected void action() {
graph.setEnableCache(false);
lastInvocation = times.getTime();
txCache.cleanUp();
}

@Override
protected void cleanup() {
graph.setEnableCache(false);
txCache.cleanUp();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public abstract class JanusGraphBlueprintsGraph implements JanusGraph {

private ThreadLocal<JanusGraphBlueprintsTransaction> txs = ThreadLocal.withInitial(() -> null);

private final ThreadLocal<Boolean> cacheEnabled = ThreadLocal.withInitial(()-> true);

public abstract JanusGraphTransaction newThreadBoundTransaction();

private JanusGraphBlueprintsTransaction getAutoStartTx() {
Expand All @@ -94,6 +96,13 @@ public JanusGraphTransaction getCurrentThreadTx() {
return getAutoStartTx();
}

public void setEnableCache(boolean enableCache) {
this.cacheEnabled.set(enableCache);
}

public boolean isCacheEnabled() {
return this.cacheEnabled.get();
}

@Override
public synchronized void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ public JanusGraphMultiVertexQuery multiQuery(Collection<JanusGraphVertex> vertic
}

public void executeMultiQuery(final Collection<InternalVertex> vertices, final SliceQuery sq, final QueryProfiler profiler) {
if(!getGraph().isCacheEnabled()) {
txHandle.disableCache();
}
LongArrayList vertexIds = new LongArrayList(vertices.size());
for (InternalVertex v : vertices) {
if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq)) vertexIds.add(v.longId());
Expand Down Expand Up @@ -1409,6 +1412,9 @@ else if (query.getResultType() == ElementCategory.VERTEX) {
@Override
public Iterator<JanusGraphElement> execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) {
Iterator<JanusGraphElement> iterator;
if(!getGraph().isCacheEnabled()) {
txHandle.disableCache();
}
if (!indexQuery.isEmpty()) {
final List<QueryUtil.IndexCall<Object>> retrievals = new ArrayList<>();
// Leave first index for streaming, and prepare the rest for intersecting and lookup
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-cql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
</parent>

<artifactId>janusgraph-cql</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-doc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-driver</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-es/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-es</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-berkeleyje/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-berkeleyje</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-cql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-cql</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-hbase</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-remotegraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-remotegraph</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/example-tinkergraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-tinkergraph</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
</parent>
<artifactId>janusgraph-grpc</artifactId>
<name>JanusGraph-gRPC: gRPC Components for JanusGraph</name>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-hadoop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-hadoop</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
</parent>
<artifactId>janusgraph-hbase</artifactId>
<name>JanusGraph-HBase: Distributed Graph Database</name>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-inmemory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-inmemory</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-lucene/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-lucene</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
</parent>
<artifactId>janusgraph-server</artifactId>
<name>JanusGraph-Server: Server Components for JanusGraph</name>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-solr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-solr</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion janusgraph-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>janusgraph-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph</artifactId>
<version>0.6.01</version>
<version>0.6.02</version>
<packaging>pom</packaging>
<prerequisites>
<maven>3.0.0</maven>
Expand Down

0 comments on commit e7209e1

Please sign in to comment.