Skip to content
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

[Dataflow Streaming] Invalidate caches and remove work on failure before commit #30229

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1397,12 +1397,21 @@ private void commitLoop() {
// Adds the commit to the commitStream if it fits, returning true iff it is consumed.
private boolean addCommitToStream(Commit commit, CommitWorkStream commitStream) {
Preconditions.checkNotNull(commit);
final ComputationState state = commit.computationState();
final Windmill.WorkItemCommitRequest request = commit.request();
// Drop commits for failed work. Such commits will be dropped by Windmill anyway.
if (commit.work().isFailed()) {
readerCache.invalidateReader(
WindmillComputationKey.create(
state.getComputationId(), request.getKey(), request.getShardingKey()));
stateCache
.forComputation(state.getComputationId())
.invalidate(request.getKey(), request.getShardingKey());
state.completeWorkAndScheduleNextWorkForKey(
ShardedKey.create(request.getKey(), request.getShardingKey()), request.getWorkToken());
return true;
}
final ComputationState state = commit.computationState();
final Windmill.WorkItemCommitRequest request = commit.request();

final int size = commit.getSize();
commit.work().setState(Work.State.COMMITTING);
activeCommitBytes.addAndGet(size);
Expand All @@ -1419,8 +1428,6 @@ private boolean addCommitToStream(Commit commit, CommitWorkStream commitStream)
.invalidate(request.getKey(), request.getShardingKey());
}
activeCommitBytes.addAndGet(-size);
// This may throw an exception if the commit was not active, which is possible if it
// was deemed stuck.
state.completeWorkAndScheduleNextWorkForKey(
ShardedKey.create(request.getKey(), request.getShardingKey()),
request.getWorkToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,13 @@ synchronized Optional<Work> completeWorkAndGetNextWorkForKey(

private synchronized void removeCompletedWorkFromQueue(
Queue<Work> workQueue, ShardedKey shardedKey, long workToken) {
// avoid Preconditions.checkState here to prevent eagerly evaluating the
// format string parameters for the error message.
Work completedWork =
Optional.ofNullable(workQueue.peek())
.orElseThrow(
() ->
new IllegalStateException(
String.format(
"Active key %s without work, expected token %d",
shardedKey, workToken)));
Work completedWork = workQueue.peek();
if (completedWork == null) {
// Work may have been completed due to clearing of stuck commits.
LOG.warn(
String.format("Active key %s without work, expected token %d", shardedKey, workToken));
return;
}

if (completedWork.getWorkItem().getWorkToken() != workToken) {
// Work may have been completed due to clearing of stuck commits.
Expand Down
Loading