-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lazy load relations and cached query optimization
Signed-off-by: ntisseyre <ntisseyre@apple.com>
- Loading branch information
Showing
19 changed files
with
730 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ph-backend-testutils/src/main/java/org/janusgraph/graphdb/database/LazyLoadGraphTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2024 JanusGraph Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.janusgraph.graphdb.database; | ||
|
||
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies; | ||
import org.apache.tinkerpop.gremlin.structure.Graph; | ||
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexFilterOptimizerStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasIdOptimizerStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexHasUniquePropertyOptimizerStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.AdjacentVertexIsOptimizerStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphHasStepStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphIoRegistrationStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphLocalQueryOptimizerStrategy; | ||
import org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexAggStrategy; | ||
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.tinkerpop.optimize.strategy.JanusGraphUnusedMultiQueryRemovalStrategy; | ||
import org.janusgraph.graphdb.transaction.StandardTransactionBuilder; | ||
|
||
public class LazyLoadGraphTest extends StandardJanusGraph { | ||
|
||
static { | ||
TraversalStrategies graphStrategies = | ||
TraversalStrategies.GlobalCache.getStrategies(Graph.class) | ||
.clone() | ||
.addStrategies(AdjacentVertexFilterOptimizerStrategy.instance(), | ||
AdjacentVertexHasIdOptimizerStrategy.instance(), | ||
AdjacentVertexIsOptimizerStrategy.instance(), | ||
AdjacentVertexHasUniquePropertyOptimizerStrategy.instance(), | ||
JanusGraphLocalQueryOptimizerStrategy.instance(), | ||
JanusGraphHasStepStrategy.instance(), | ||
JanusGraphMultiQueryStrategy.instance(), | ||
JanusGraphUnusedMultiQueryRemovalStrategy.instance(), | ||
JanusGraphMixedIndexAggStrategy.instance(), | ||
JanusGraphMixedIndexCountStrategy.instance(), | ||
JanusGraphStepStrategy.instance(), | ||
JanusGraphIoRegistrationStrategy.instance()); | ||
|
||
//Register with cache | ||
TraversalStrategies.GlobalCache.registerStrategies(LazyLoadGraphTest.class, graphStrategies); | ||
} | ||
|
||
public LazyLoadGraphTest(GraphDatabaseConfiguration configuration) { | ||
super(configuration); | ||
} | ||
|
||
@Override | ||
public StandardTransactionBuilder buildTransaction() { | ||
return (StandardTransactionBuilder) new StandardTransactionBuilder(getConfiguration(), this) | ||
.lazyLoadRelations(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
janusgraph-core/src/main/java/org/janusgraph/core/JanusGraphLazyEdge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 JanusGraph Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.janusgraph.core; | ||
|
||
import org.apache.tinkerpop.gremlin.structure.Direction; | ||
import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
import org.janusgraph.diskstorage.Entry; | ||
import org.janusgraph.graphdb.internal.InternalRelation; | ||
import org.janusgraph.graphdb.internal.InternalRelationType; | ||
import org.janusgraph.graphdb.internal.InternalVertex; | ||
import org.janusgraph.graphdb.transaction.StandardJanusGraphTx; | ||
|
||
public class JanusGraphLazyEdge extends JanusGraphLazyRelation implements JanusGraphEdge { | ||
|
||
public JanusGraphLazyEdge(InternalRelation janusGraphRelation, | ||
final InternalVertex vertex, | ||
final StandardJanusGraphTx tx, | ||
final InternalRelationType type) { | ||
super(janusGraphRelation, vertex, tx, type); | ||
} | ||
|
||
public JanusGraphLazyEdge(Entry dataEntry, | ||
final InternalVertex vertex, | ||
final StandardJanusGraphTx tx, | ||
final InternalRelationType type) { | ||
super(dataEntry, vertex, tx, type); | ||
} | ||
|
||
private JanusGraphEdge loadEdge() { | ||
assert this.isEdge(); | ||
return (JanusGraphEdge) this.loadValue(); | ||
} | ||
|
||
@Override | ||
public JanusGraphVertex vertex(Direction dir) { | ||
return this.loadEdge().vertex(dir); | ||
} | ||
|
||
@Override | ||
public JanusGraphVertex otherVertex(Vertex vertex) { | ||
return this.loadEdge().otherVertex(vertex); | ||
} | ||
} |
Oops, something went wrong.