Skip to content

Commit

Permalink
Serialize using codec version
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
  • Loading branch information
soosinha committed Oct 21, 2024
1 parent a53e0c6 commit 4ea63a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1216,12 +1216,18 @@ private static String componentPrefix(Object[] fields) {

private static final ConstructingObjectParser<UploadedIndexMetadata, Void> PARSER_V0 = new ConstructingObjectParser<>(
"uploaded_index_metadata",
fields -> new UploadedIndexMetadata(indexName(fields), indexUUID(fields), uploadedFilename(fields))
fields -> new UploadedIndexMetadata(indexName(fields), indexUUID(fields), uploadedFilename(fields), CODEC_V0)
);

private static final ConstructingObjectParser<UploadedIndexMetadata, Void> PARSER_V2 = new ConstructingObjectParser<>(
"uploaded_index_metadata",
fields -> new UploadedIndexMetadata(indexName(fields), indexUUID(fields), uploadedFilename(fields), componentPrefix(fields))
fields -> new UploadedIndexMetadata(
indexName(fields),
indexUUID(fields),
uploadedFilename(fields),
componentPrefix(fields),
CODEC_V2
)
);

private static final ConstructingObjectParser<UploadedIndexMetadata, Void> CURRENT_PARSER = PARSER_V2;
Expand Down Expand Up @@ -1306,6 +1312,10 @@ public String getComponentPrefix() {
return componentPrefix;
}

protected void setCodecVersion(long codecVersion) {
this.codecVersion = codecVersion;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(INDEX_NAME_FIELD.getPreferredName(), getIndexName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ RemoteClusterStateManifestInfo uploadManifest(
) {
synchronized (this) {
ClusterMetadataManifest.Builder manifestBuilder = ClusterMetadataManifest.builder();
uploadedMetadataResult.uploadedIndexMetadata.forEach(md -> md.setCodecVersion(codecVersion));
manifestBuilder.clusterTerm(clusterState.term())
.stateVersion(clusterState.getVersion())
.clusterUUID(clusterState.metadata().clusterUUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public UploadedMetadata getUploadedMetadata() {

@Override
public InputStream serialize() throws IOException {
return CLUSTER_METADATA_MANIFEST_FORMAT.serialize(
ChecksumBlobStoreFormat<ClusterMetadataManifest> blobStoreFormat = getClusterMetadataManifestBlobStoreFormatForUpload();
return blobStoreFormat.serialize(
clusterMetadataManifest,
generateBlobFileName(),
getCompressor(),
Expand All @@ -133,7 +134,7 @@ public InputStream serialize() throws IOException {

@Override
public ClusterMetadataManifest deserialize(final InputStream inputStream) throws IOException {
ChecksumBlobStoreFormat<ClusterMetadataManifest> blobStoreFormat = getClusterMetadataManifestBlobStoreFormat();
ChecksumBlobStoreFormat<ClusterMetadataManifest> blobStoreFormat = getClusterMetadataManifestBlobStoreFormatForDownload();
return blobStoreFormat.deserialize(blobName, getNamedXContentRegistry(), Streams.readFully(inputStream));
}

Expand All @@ -151,8 +152,17 @@ int getManifestCodecVersion() {
}
}

private ChecksumBlobStoreFormat<ClusterMetadataManifest> getClusterMetadataManifestBlobStoreFormat() {
private ChecksumBlobStoreFormat<ClusterMetadataManifest> getClusterMetadataManifestBlobStoreFormatForDownload() {
long codecVersion = getManifestCodecVersion();
return getClusterMetadataManifestBlobStoreFormat(codecVersion);
}

private ChecksumBlobStoreFormat<ClusterMetadataManifest> getClusterMetadataManifestBlobStoreFormatForUpload() {
long codecVersion = clusterMetadataManifest.getCodecVersion();
return getClusterMetadataManifestBlobStoreFormat(codecVersion);
}

private ChecksumBlobStoreFormat<ClusterMetadataManifest> getClusterMetadataManifestBlobStoreFormat(long codecVersion) {
if (codecVersion == ClusterMetadataManifest.MANIFEST_CURRENT_CODEC_VERSION) {
return CLUSTER_METADATA_MANIFEST_FORMAT;
} else if (codecVersion == ClusterMetadataManifest.CODEC_V3) {
Expand Down

0 comments on commit 4ea63a5

Please sign in to comment.