Skip to content

Commit

Permalink
Returning a copied collection to avoid corrupted iterator by multiple…
Browse files Browse the repository at this point in the history
… threads

Signed-off-by: ntisseyre <[email protected]>
  • Loading branch information
ntisseyre authored and porunov committed Mar 4, 2024
1 parent 54073ca commit c9e0e27
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ public synchronized void commit() {
}
try {
if (hasModifications()) {
graph.commit(addedRelations.getAll(), deletedRelations.values(), this);
graph.commit(addedRelations.getAllUnsafe(), deletedRelations.values(), this);
} else {
txHandle.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface AddedRelationsContainer {
* of the transaction after there are no additional changes. Otherwise the behavior is non deterministic.
* @return
*/
Collection<InternalRelation> getAll();
Collection<InternalRelation> getAllUnsafe();

/**
* Clears the container which releases allocated memory.
Expand Down Expand Up @@ -69,7 +69,7 @@ public boolean isEmpty() {
}

@Override
public Collection<InternalRelation> getAll() {
public Collection<InternalRelation> getAllUnsafe() {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package org.janusgraph.graphdb.transaction.addedrelations;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.janusgraph.graphdb.internal.InternalRelation;

import java.util.ArrayList;
import java.util.Collection;

/**
Expand All @@ -37,11 +39,17 @@ public synchronized boolean remove(final InternalRelation relation) {

@Override
public synchronized Iterable<InternalRelation> getView(final Predicate<InternalRelation> filter) {
return super.getView(filter);
return copyView(super.getView(filter));
}

@Override
public synchronized Collection<InternalRelation> getAll() {
return super.getAll();
public synchronized Collection<InternalRelation> getAllUnsafe() {
return super.getAllUnsafe();
}

private Iterable<InternalRelation> copyView(Iterable<InternalRelation> currentView) {
ArrayList<InternalRelation> view = new ArrayList<>();
Iterables.addAll(view, currentView);
return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean isEmpty() {
}

@Override
public Collection<InternalRelation> getAll() {
public Collection<InternalRelation> getAllUnsafe() {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean isEmpty() {
}

@Override
public Collection<InternalRelation> getAll() {
public Collection<InternalRelation> getAllUnsafe() {
return Collections.unmodifiableCollection(new AbstractCollection<InternalRelation>() {
@Override
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void isEmpty() {
}

@Test
public void getAllReturnsEmpty() {
assertTrue(EmptyAddedRelations.getInstance().getAll().isEmpty());
public void getAllUnsafeReturnsEmpty() {
assertTrue(EmptyAddedRelations.getInstance().getAllUnsafe().isEmpty());
}

@Test
Expand Down

1 comment on commit c9e0e27

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: c9e0e27 Previous: 1530f0a Ratio
org.janusgraph.JanusGraphSpeedBenchmark.basicAddAndDelete 11975.991611931706 ms/op 12385.880105942719 ms/op 0.97
org.janusgraph.GraphCentricQueryBenchmark.getVertices 891.9993122162828 ms/op 897.5208673932261 ms/op 0.99
org.janusgraph.MgmtOlapJobBenchmark.runClearIndex 215.43794450833335 ms/op 216.14179947499997 ms/op 1.00
org.janusgraph.MgmtOlapJobBenchmark.runReindex 338.20706768821435 ms/op 332.1309897483333 ms/op 1.02
org.janusgraph.JanusGraphSpeedBenchmark.basicCount 206.48818390707245 ms/op 215.02071580531708 ms/op 0.96
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 4745.627802571131 ms/op 4664.188207695399 ms/op 1.02
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingEmitRepeatSteps 16359.944287511313 ms/op 16352.527830474333 ms/op 1.00
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithSmallBatch 19687.685982958785 ms/op 19824.599960445456 ms/op 0.99
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.vertexCentricPropertiesFetching 56911.53172566667 ms/op 56201.26617166666 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getAllElementsTraversedFromOuterVertex 8024.220524112066 ms/op 7906.645219600678 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithDoubleUnion 379.6767445490278 ms/op 379.8377001964137 ms/op 1.00
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithUnlimitedBatch 3979.9422536534776 ms/op 3886.8713759808343 ms/op 1.02
org.janusgraph.CQLMultiQueryBenchmark.getNames 8011.535199335706 ms/op 8135.59305787296 ms/op 0.98
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesThreePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 5815.267118299681 ms/op 5503.356218245031 ms/op 1.06
org.janusgraph.CQLMultiQueryBenchmark.getLabels 6869.1157300562345 ms/op 7024.7527374147185 ms/op 0.98
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFilteredByAndStep 425.2261499161585 ms/op 427.17314494545025 ms/op 1.00
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFromMultiNestedRepeatStepStartingFromSingleVertex 12762.557303115294 ms/op 11926.323378581046 ms/op 1.07
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithCoalesceUsage 355.3501511026233 ms/op 361.90201198876565 ms/op 0.98
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 13640.597454835 ms/op 13280.235397442804 ms/op 1.03
org.janusgraph.CQLMultiQueryBenchmark.getIdToOutVerticesProjection 242.20685558070096 ms/op 245.53304211034066 ms/op 0.99
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithUnlimitedBatch 13843.400991503633 ms/op 13693.67385197527 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getNeighborNames 8220.676566548367 ms/op 8163.851328829417 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingRepeatUntilSteps 9097.280539574827 ms/op 8777.982757626436 ms/op 1.04
org.janusgraph.CQLMultiQueryBenchmark.getAdjacentVerticesLocalCounts 8383.346967098938 ms/op 8487.195678565702 ms/op 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.