@Override public CopycatException createException() { return new UnknownSessionException("unknown member session"); } },
@Override public CopycatException createException() { return new UnknownSessionException("unknown member session"); } },
@Override public CopycatException createException() { return new UnknownSessionException("unknown member session"); } },
/** * Executes a state machine query. */ private void executeQuery(ServerCommit commit, ServerSessionContext session, CompletableFuture<Object> future, ThreadContext context) { if (!log.isOpen()) { context.executor().execute(() -> future.completeExceptionally(new IllegalStateException("log closed"))); return; } // If the session is already in an inactive state, complete the future exceptionally. if (!session.state().active()) { context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return; } // Update the state machine context with the query entry's index. We set a null consistency // level to indicate that events cannot be published in this context. Publishing events in // response to state machine queries is non-deterministic as queries are not replicated. executor.init(commit.index(), commit.time(), true, null); try { Object result = executor.executeOperation(commit); context.executor().execute(() -> future.complete(result)); } catch (Exception e) { context.executor().execute(() -> future.completeExceptionally(e)); } }
/** * Executes a state machine query. */ private void executeQuery(ServerCommit commit, ServerSessionContext session, CompletableFuture<Result> future, ThreadContext context) { if (!log.isOpen()) { context.executor().execute(() -> future.completeExceptionally(new IllegalStateException("log closed"))); return; } // If the session is already in an inactive state, complete the future exceptionally. if (!session.state().active()) { context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return; } long index = commit.index(); long eventIndex = session.getEventIndex(); // Update the state machine context with the query entry's index. We set a null consistency // level to indicate that events cannot be published in this context. Publishing events in // response to state machine queries is non-deterministic as queries are not replicated. executor.init(index, commit.time(), ServerStateMachineContext.Type.QUERY); try { Object result = executor.executeOperation(commit); context.executor().execute(() -> future.complete(new Result(index, eventIndex, result))); } catch (Exception e) { context.executor().execute(() -> future.complete(new Result(index, eventIndex, e))); } }
/** * Executes a state machine query. */ private void executeQuery(ServerCommit commit, ServerSessionContext session, CompletableFuture<Result> future, ThreadContext context) { if (!log.isOpen()) { context.executor().execute(() -> future.completeExceptionally(new IllegalStateException("log closed"))); return; } // If the session is already in an inactive state, complete the future exceptionally. if (!session.state().active()) { context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return; } long index = commit.index(); long eventIndex = session.getEventIndex(); // Update the state machine context with the query entry's index. We set a null consistency // level to indicate that events cannot be published in this context. Publishing events in // response to state machine queries is non-deterministic as queries are not replicated. executor.init(index, commit.time(), ServerStateMachineContext.Type.QUERY); try { Object result = executor.executeOperation(commit); context.executor().execute(() -> future.complete(new Result(index, eventIndex, result))); } catch (Exception e) { context.executor().execute(() -> future.complete(new Result(index, eventIndex, e))); } }
/** * Applies a keep alive for a session. */ private void keepAliveSession(long index, long timestamp, long commandSequence, long eventIndex, ServerSessionContext session, CompletableFuture<Void> future, ThreadContext context) { if (!log.isOpen()) { context.executor().execute(() -> future.completeExceptionally(new IllegalStateException("log closed"))); return; } // If the session is already in an inactive state, complete the future exceptionally. if (!session.state().active()) { context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return; } // Trigger scheduled callbacks in the state machine. executor.tick(index, timestamp); // Update the state machine context with the keep-alive entry's index. This ensures that events published // as a result of asynchronous callbacks will be executed at the proper index with SEQUENTIAL consistency. executor.init(index, Instant.ofEpochMilli(timestamp), ServerStateMachineContext.Type.COMMAND); session.clearResults(commandSequence).resendEvents(eventIndex); // Calculate the last completed index. long lastCompleted = calculateLastCompleted(index); // Callbacks in the state machine may have been triggered by the execution of the keep-alive. // Get any futures for scheduled tasks and await their completion, then update the highest // index completed for all sessions to allow log compaction to progress. executor.commit(); context.executor().execute(() -> { setLastCompleted(lastCompleted); future.complete(null); }); }
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
/** * Applies a keep alive for a session. */ private void keepAliveSession(long index, long timestamp, long commandSequence, long eventIndex, ServerSessionContext session, CompletableFuture<Void> future, ThreadContext context) { if (!log.isOpen()) { context.executor().execute(() -> future.completeExceptionally(new IllegalStateException("log closed"))); return; } // If the session is already in an inactive state, complete the future exceptionally. if (!session.state().active()) { context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return; } // Trigger scheduled callbacks in the state machine. executor.tick(index, timestamp); // Update the state machine context with the keep-alive entry's index. This ensures that events published // as a result of asynchronous callbacks will be executed at the proper index with SEQUENTIAL consistency. executor.init(index, Instant.ofEpochMilli(timestamp), ServerStateMachineContext.Type.COMMAND); session.clearResults(commandSequence).resendEvents(eventIndex); // Calculate the last completed index. long lastCompleted = calculateLastCompleted(index); // Callbacks in the state machine may have been triggered by the execution of the keep-alive. // Get any futures for scheduled tasks and await their completion, then update the highest // index completed for all sessions to allow log compaction to progress. executor.commit(); context.executor().execute(() -> { setLastCompleted(lastCompleted); future.complete(null); }); }
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
context.executor().execute(() -> future.completeExceptionally(new UnknownSessionException("inactive session: " + session.id()))); return;
return Futures.exceptionalFuture(new UnknownSessionException("unknown session " + entry.getSession())); return Futures.exceptionalFuture(new UnknownSessionException("inactive session: " + entry.getSession())); } else { CompletableFuture<Result> future = new CompletableFuture<>();
return Futures.exceptionalFuture(new UnknownSessionException("unknown session " + entry.getSession())); return Futures.exceptionalFuture(new UnknownSessionException("inactive session: " + entry.getSession())); } else { CompletableFuture<Result> future = new CompletableFuture<>();
future = Futures.exceptionalFuture(new UnknownSessionException("unknown session: " + entry.getSession())); future = Futures.exceptionalFuture(new UnknownSessionException("inactive session: " + entry.getSession()));