Skip to content

Commit

Permalink
Merge pull request #60 from Netflix/renameTinkerpop
Browse files Browse the repository at this point in the history
renaming useTinkerpop to useJanusgraphTransaction
  • Loading branch information
ipapapa authored Nov 1, 2017
2 parents 71444b9 + 9cebb41 commit 508c685
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@
import java.util.List;

/***
* JanusGraph benchmarking plugin to measure throughput of write and read by single ID using JanusGraph Core API
* JanusGraph benchmarking plugin to measure throughput of write and read by
* single ID using JanusGraph Core API
*
* @author pencal
*/
@Singleton
@NdBenchClientPlugin("janusgraph-cql")
public class JanusGraphPluginCQL extends JanusGraphBasePlugin implements NdBenchClient {
private static final Logger LOG = LoggerFactory.getLogger(JanusGraphPluginCQL.class);
private static final Logger Logger = LoggerFactory.getLogger(JanusGraphPluginCQL.class);
private static String BACKEND = "cql";

private final JanusGraphFactory.Builder graphBuilder;

private DataGenerator dataGenerator;
private GraphTraversalSource traversalSource;
private JanusGraph graph;
private boolean useTinkerPop;
private boolean useJanusgraphTransaction;

@Inject
public JanusGraphPluginCQL(IJanusGraphConfig config, JanusGraphBuilderCQLProvider builderProvider) {
super(BACKEND, config.getStorageHostname(), config.getStoragePort());
this.graphBuilder = builderProvider.getGraphBuilder();
this.useTinkerPop = config.isUsingTinkerpop();
this.useJanusgraphTransaction = config.useJanusgraphTransaction();
}

@Override
Expand All @@ -57,43 +58,41 @@ public void init(DataGenerator dataGenerator) throws Exception {
@Override
public String readSingle(String key) throws Exception {
String response = OK;
if (useTinkerPop) {
if (useJanusgraphTransaction) {
try (JanusGraphTransaction tx = graph.newTransaction()) {
Iterator<JanusGraphVertex> result = tx.query().has(PROP_CUSTOM_ID_KEY, key).vertices().iterator();
if (result == null)
throw new Exception(
"Internal error when reading data with key" + key + " using JanusGraph Core API");
else if (!result.hasNext())
response = CACHE_MISS;
}
} else {
List<Vertex> results = traversalSource.V().has(PROP_CUSTOM_ID_KEY, key).toList();

if (results == null)
throw new Exception("Internal error when reading data with key" + key + " using TinkerPop API");
else if (results.size() == 0)
response = CACHE_MISS;
}
else {
try(JanusGraphTransaction tx = graph.newTransaction()) {
Iterator<JanusGraphVertex> result = tx.query().has(PROP_CUSTOM_ID_KEY, key).vertices().iterator();
if (result == null)
throw new Exception("Internal error when reading data with key" + key + " using JanusGraph Core API");
else if (!result.hasNext())
response = CACHE_MISS;
}
}

return response;
}

@Override
public String writeSingle(String key) throws Exception {
if (useTinkerPop) {
if (useJanusgraphTransaction) {
try (JanusGraphTransaction tx = graph.newTransaction()) {
tx.addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key, PROP_METADATA_KEY,
dataGenerator.getRandomValue());
tx.commit();
}
} else {
Transaction tx = traversalSource.tx();
tx.open();
traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1
, PROP_CUSTOM_ID_KEY, key
, PROP_METADATA_KEY, dataGenerator.getRandomValue());
traversalSource.getGraph().addVertex(T.label, VERTEX_LABEL_LEVEL_1, PROP_CUSTOM_ID_KEY, key,
PROP_METADATA_KEY, dataGenerator.getRandomValue());
tx.commit();
} else {
try(JanusGraphTransaction tx = graph.newTransaction()) {
tx.addVertex(T.label, VERTEX_LABEL_LEVEL_1
, PROP_CUSTOM_ID_KEY, key
, PROP_METADATA_KEY, dataGenerator.getRandomValue());
tx.commit();
}
}

return OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Configuration(prefix = "ndbench.config.janusgraph")
public interface IJanusGraphConfig {
// One can benchmark either the Tinkerpop API or the JanusGraph Core API if needed
@DefaultValue("true")
boolean isUsingTinkerpop();
@DefaultValue("false")
boolean useJanusgraphTransaction();

@DefaultValue("127.0.0.1")
String getStorageHostname();
Expand Down

0 comments on commit 508c685

Please sign in to comment.