use of org.neo4j.io.pagecache.context.VersionContext in project neo4j by neo4j.
the class SnapshotExecutionEngine method executeWithRetries.
protected MaterialisedResult executeWithRetries(String query, TransactionalContext context, QueryExecutor executor) throws QueryExecutionKernelException {
VersionContext versionContext = getCursorContext(context);
MaterialisedResult materialisedResult;
int attempt = 0;
boolean dirtySnapshot;
do {
if (attempt == maxQueryExecutionAttempts) {
throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' after %d attempts.", query, attempt));
}
if (attempt > 0) {
context.executingQuery().onRetryAttempted();
}
attempt++;
versionContext.initRead();
materialisedResult = new MaterialisedResult();
QueryExecution queryExecution = executor.execute(materialisedResult);
materialisedResult.consumeAll(queryExecution);
// objects is guaranteed by schema and not by execution engine
if (context.transaction().kernelTransaction().isSchemaTransaction()) {
return materialisedResult;
}
dirtySnapshot = versionContext.isDirty();
if (isUnstableSnapshot(materialisedResult, dirtySnapshot)) {
throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' that performs updates.", query, attempt));
}
} while (dirtySnapshot);
return materialisedResult;
}
use of org.neo4j.io.pagecache.context.VersionContext in project neo4j by neo4j.
the class SnapshotExecutionEngineTest method setUp.
@BeforeEach
void setUp() throws Exception {
transactionalContext = mock(TransactionalContext.class, RETURNS_DEEP_STUBS);
KernelStatement kernelStatement = mock(KernelStatement.class);
executor = mock(SnapshotExecutionEngine.QueryExecutor.class);
versionContext = mock(VersionContext.class);
statistics = mock(QueryStatistics.class);
executionEngine = new SnapshotExecutionEngine(new GraphDatabaseCypherService(db), config, TestExecutorCaffeineCacheFactory$.MODULE$, NullLogProvider.getInstance(), mock(CompilerFactory.class));
when(transactionalContext.kernelTransaction().cursorContext()).thenReturn(new CursorContext(NULL, versionContext));
when(transactionalContext.statement()).thenReturn(kernelStatement);
var innerExecution = mock(QueryExecution.class);
when(executor.execute(any())).thenAnswer((Answer<QueryExecution>) invocationOnMock -> {
MaterialisedResult materialisedResult = invocationOnMock.getArgument(0);
materialisedResult.onResultCompleted(statistics);
return innerExecution;
});
}
Aggregations