Skip to content

Commit

Permalink
Use latest codec version when publication is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed Oct 22, 2024
1 parent 5137b75 commit 9317040
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public PublicationContext newPublicationContext(
}

private boolean validateRemotePublicationConfiguredOnAllNodes(DiscoveryNodes discoveryNodes) {
assert ClusterMetadataManifest.getCodecForVersion(discoveryNodes.getMinNodeVersion()) >= ClusterMetadataManifest.CODEC_V0;
assert ClusterMetadataManifest.getCodecForVersion(discoveryNodes.getMinNodeVersion(), true) >= ClusterMetadataManifest.CODEC_V0;
for (DiscoveryNode node : discoveryNodes.getNodes().values()) {
// if a node is non-remote then created local publication context
if (node.isRemoteStatePublicationEnabled() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,10 @@ public void setLastAcceptedState(ClusterState clusterState) {
try {
final RemoteClusterStateManifestInfo manifestDetails;
// Decide the codec version
int codecVersion = ClusterMetadataManifest.getCodecForVersion(clusterState.nodes().getMinNodeVersion());
int codecVersion = ClusterMetadataManifest.getCodecForVersion(
clusterState.nodes().getMinNodeVersion(),
remoteClusterStateService.isRemotePublicationEnabled()
);
assert codecVersion >= 0 : codecVersion;
logger.info("codec version is {}", codecVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ private static ClusterStateChecksum checksum(Object[] fields) {
VERSION_TO_CODEC_MAPPING = Collections.unmodifiableMap(versionToCodecMapping);
}

public static int getCodecForVersion(Version version) {
public static int getCodecForVersion(Version version, boolean isPublicationEnabled) {
if (!isPublicationEnabled) {
return MANIFEST_CURRENT_CODEC_VERSION;
}
return VERSION_TO_CODEC_MAPPING.getOrDefault(version, -1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ public void testRemotePersistedStateWithDifferentNodeConfiguration() throws IOEx
.build();
Mockito.when(remoteClusterStateService.writeFullMetadata(Mockito.any(), Mockito.any(), eq(CODEC_V1)))
.thenReturn(new RemoteClusterStateManifestInfo(manifest, "path/to/manifest2"));
Mockito.when(remoteClusterStateService.isRemotePublicationEnabled()).thenReturn(true);

CoordinationState.PersistedState remotePersistedState = new RemotePersistedState(remoteClusterStateService, previousClusterUUID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,14 @@ public void testUploadedIndexMetadataWithoutComponentPrefix() throws IOException
}

public void testGetCodecForVersion() {
assertEquals(-1, ClusterMetadataManifest.getCodecForVersion(Version.fromString("1.3.0")));
assertEquals(-1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_1_0));
assertEquals(CODEC_V0, ClusterMetadataManifest.getCodecForVersion(Version.V_2_10_0));
assertEquals(CODEC_V1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_12_0));
assertEquals(CODEC_V1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_13_0));
assertEquals(CODEC_V2, ClusterMetadataManifest.getCodecForVersion(Version.V_2_15_0));
assertEquals(CODEC_V3, ClusterMetadataManifest.getCodecForVersion(Version.V_2_16_0));
assertEquals(CODEC_V4, ClusterMetadataManifest.getCodecForVersion(Version.V_2_17_0));
assertEquals(-1, ClusterMetadataManifest.getCodecForVersion(Version.fromString("1.3.0"), true));
assertEquals(-1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_1_0, true));
assertEquals(CODEC_V0, ClusterMetadataManifest.getCodecForVersion(Version.V_2_10_0, true));
assertEquals(CODEC_V1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_12_0, true));
assertEquals(CODEC_V1, ClusterMetadataManifest.getCodecForVersion(Version.V_2_13_0, true));
assertEquals(CODEC_V2, ClusterMetadataManifest.getCodecForVersion(Version.V_2_15_0, true));
assertEquals(CODEC_V3, ClusterMetadataManifest.getCodecForVersion(Version.V_2_16_0, true));
assertEquals(CODEC_V4, ClusterMetadataManifest.getCodecForVersion(Version.V_2_17_0, true));
}

private UploadedIndexMetadata randomlyChangingUploadedIndexMetadata(UploadedIndexMetadata uploadedIndexMetadata) {
Expand Down

0 comments on commit 9317040

Please sign in to comment.