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

Fail invalid incremental cluster state writes #61030

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 @@ -455,7 +455,7 @@ public void setCurrentTerm(long currentTerm) {
getWriterSafe().writeFullStateAndCommit(currentTerm, lastAcceptedState);
writeNextStateFully = false;
} else {
getWriterSafe().commit(currentTerm, lastAcceptedState.version());
getWriterSafe().writeIncrementalTermUpdateAndCommit(currentTerm, lastAcceptedState.version());
}
} catch (Exception e) {
handleExceptionOnWrite(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ public void writeFullStateAndCommit(long currentTerm, ClusterState clusterState)
void writeIncrementalStateAndCommit(long currentTerm, ClusterState previousClusterState,
ClusterState clusterState) throws IOException {
ensureOpen();
assert fullStateWritten : "Need to write full state first before doing incremental writes";
ensureFullStateWritten();

try {
final long startTimeMillis = relativeTimeMillisSupplier.getAsLong();
final WriterStats stats = updateMetadata(previousClusterState.metadata(), clusterState.metadata());
Expand All @@ -631,6 +632,15 @@ void writeIncrementalStateAndCommit(long currentTerm, ClusterState previousClust
}
}

private void ensureFullStateWritten() {
assert fullStateWritten : "Need to write full state first before doing incremental writes";
//noinspection ConstantConditions to catch this even if assertions are disabled
if (fullStateWritten == false) {
logger.error("cannot write incremental state");
throw new IllegalStateException("cannot write incremental state");
}
}

/**
* Update the persisted metadata to match the given cluster state by removing any stale or unnecessary documents and adding any
* updated documents.
Expand Down Expand Up @@ -730,7 +740,13 @@ private WriterStats addMetadata(Metadata metadata) throws IOException {
return new WriterStats(true, metadata.indices().size(), 0);
}

public void commit(long currentTerm, long lastAcceptedVersion) throws IOException {
public void writeIncrementalTermUpdateAndCommit(long currentTerm, long lastAcceptedVersion) throws IOException {
ensureOpen();
ensureFullStateWritten();
commit(currentTerm, lastAcceptedVersion);
}

void commit(long currentTerm, long lastAcceptedVersion) throws IOException {
ensureOpen();
try {
for (MetadataIndexWriter metadataIndexWriter : metadataIndexWriters) {
Expand Down