Skip to content

Commit

Permalink
Add assertion that system index version hashes match (should fail bwc)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Feb 15, 2024
1 parent ce26543 commit f5a300b
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;

import java.util.ArrayList;
Expand Down Expand Up @@ -158,6 +159,7 @@ public ClusterState execute(BatchExecutionContext<JoinTask> batchExecutionContex
} else {
try {
CompatibilityVersions compatibilityVersions = nodeJoinTask.compatibilityVersions();
assert systemIndexVersionConsistent(compatibilityVersions.systemIndexMappingsVersion(), compatibilityVersionsMap);
Set<String> features = nodeJoinTask.features();
if (enforceVersionBarrier) {
ensureVersionBarrier(node.getVersion(), minClusterNodeVersion);
Expand Down Expand Up @@ -261,6 +263,25 @@ public ClusterState execute(BatchExecutionContext<JoinTask> batchExecutionContex
}
}

private boolean systemIndexVersionConsistent(
Map<String, SystemIndexDescriptor.MappingsVersion> newMappingsVersions,
Map<String, CompatibilityVersions> existingCompatibilityVersions
) {
for (Map.Entry<String, CompatibilityVersions> nodeCompatibility : existingCompatibilityVersions.entrySet()) {
Map<String, SystemIndexDescriptor.MappingsVersion> existingVersions = nodeCompatibility.getValue().systemIndexMappingsVersion();
for (Map.Entry<String, SystemIndexDescriptor.MappingsVersion> existingMappingVersion : existingVersions.entrySet()) {
String indexName = existingMappingVersion.getKey();
if (newMappingsVersions.containsKey(indexName)
&& existingMappingVersion.getValue().version() == newMappingsVersions.get(indexName).version()
&& existingMappingVersion.getValue().hash() != newMappingsVersions.get(indexName).hash()) {
// log warning message?
return false;
}
}
}
return true;
}

protected ClusterState.Builder becomeMasterAndTrimConflictingNodes(
ClusterState currentState,
List<? extends TaskContext<JoinTask>> taskContexts,
Expand Down

0 comments on commit f5a300b

Please sign in to comment.