-
Notifications
You must be signed in to change notification settings - Fork 844
TINKERPOP-3217 Add server option to close Session automatically. #3284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.7-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,9 @@ public class SessionOpProcessor extends AbstractEvalOpProcessor { | |
| }}; | ||
| } | ||
|
|
||
| // Determines whether to close the session after a successful COMMIT/ROLLBACK. Set during init(). | ||
| private boolean closeSessionPostGraphOp; | ||
|
|
||
| public SessionOpProcessor() { | ||
| super(false); | ||
| } | ||
|
|
@@ -154,6 +157,7 @@ public String getName() { | |
| public void init(final Settings settings) { | ||
| this.maxParameters = (int) settings.optionalProcessor(SessionOpProcessor.class).orElse(DEFAULT_SETTINGS).config. | ||
| getOrDefault(CONFIG_MAX_PARAMETERS, DEFAULT_MAX_PARAMETERS); | ||
| this.closeSessionPostGraphOp = settings.closeSessionPostGraphOp; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -546,6 +550,13 @@ protected void handleGraphOperation(final Bytecode bytecode, final Graph graph, | |
| .statusAttributes(attributes) | ||
| .create()); | ||
|
|
||
| if (closeSessionPostGraphOp) { | ||
| // Setting force to true prevents deadlock when this thread attempts to destroy the session. | ||
| // This should be safe since either a commit or rollback just finished so the transaction | ||
| // shouldn't be open. | ||
| session.manualKill(true); | ||
| } | ||
|
|
||
| } catch (Throwable t) { | ||
| onError(graph, context); | ||
| // if any exception in the chain is TemporaryException or Failure then we should respond with the | ||
|
|
@@ -571,6 +582,13 @@ protected void handleGraphOperation(final Bytecode bytecode, final Graph graph, | |
| .statusMessage(t.getMessage()) | ||
| .statusAttributeException(t).create()); | ||
| } | ||
|
|
||
| if (closeSessionPostGraphOp && shouldManageTransactionsForRequest(context)) { | ||
| // Destroy the session after a successful rollback due to error. Placed here rather than | ||
| // in a finally block since we don't want to end the session if no commit/rollback succeeded. | ||
| session.manualKill(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is in a catch block that is catching all error types, is it possible for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't happen, but even if it does, theres explicit handling in that method for that situation so it's safe to call it more than once. |
||
| } | ||
|
|
||
| if (t instanceof Error) { | ||
| //Re-throw any errors to be handled by and set as the result the FutureTask | ||
| throw t; | ||
|
|
@@ -589,20 +607,17 @@ protected void handleGraphOperation(final Bytecode bytecode, final Graph graph, | |
| } | ||
|
|
||
| protected void beforeProcessing(final Graph graph, final Context ctx) { | ||
| final boolean managedTransactionsForRequest = manageTransactions ? | ||
| true : (Boolean) ctx.getRequestMessage().getArgs().getOrDefault(Tokens.ARGS_MANAGE_TRANSACTION, false); | ||
| final boolean managedTransactionsForRequest = shouldManageTransactionsForRequest(ctx); | ||
| if (managedTransactionsForRequest && graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().rollback(); | ||
| } | ||
|
|
||
| protected void onError(final Graph graph, final Context ctx) { | ||
| final boolean managedTransactionsForRequest = manageTransactions ? | ||
| true : (Boolean) ctx.getRequestMessage().getArgs().getOrDefault(Tokens.ARGS_MANAGE_TRANSACTION, false); | ||
| final boolean managedTransactionsForRequest = shouldManageTransactionsForRequest(ctx); | ||
| if (managedTransactionsForRequest && graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().rollback(); | ||
| } | ||
|
|
||
| protected void onTraversalSuccess(final Graph graph, final Context ctx) { | ||
| final boolean managedTransactionsForRequest = manageTransactions ? | ||
| true : (Boolean) ctx.getRequestMessage().getArgs().getOrDefault(Tokens.ARGS_MANAGE_TRANSACTION, false); | ||
| final boolean managedTransactionsForRequest = shouldManageTransactionsForRequest(ctx); | ||
| if (managedTransactionsForRequest && graph.features().graph().supportsTransactions() && graph.tx().isOpen()) graph.tx().commit(); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.