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

Change filenames for IndexMetadata and Manifest #10557

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Implement on behalf of token passing for extensions ([#8679](https://github.com/opensearch-project/OpenSearch/pull/8679))
- Provide service accounts tokens to extensions ([#9618](https://github.com/opensearch-project/OpenSearch/pull/9618))
- [Admission control] Add Resource usage collector service and resource usage tracker ([#9890](https://github.com/opensearch-project/OpenSearch/pull/9890))
- Change file names for remote cluster state ([#10557](https://github.com/opensearch-project/OpenSearch/pull/10557))

### Dependencies
- Bump `log4j-core` from 2.18.0 to 2.19.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public class RemoteClusterStateService implements Closeable {

private final AtomicBoolean deleteStaleMetadataRunning = new AtomicBoolean(false);

private static final int INDEX_METADATA_CODEC_VERSION = 1;
private static final int MANIFEST_CODEC_VERSION = 2;

public RemoteClusterStateService(
String nodeId,
Supplier<RepositoriesService> repositoriesService,
Expand Down Expand Up @@ -426,7 +429,7 @@ private ClusterMetadataManifest uploadManifest(
boolean committed
) throws IOException {
synchronized (this) {
final String manifestFileName = getManifestFileName(clusterState.term(), clusterState.version());
final String manifestFileName = getManifestFileName(clusterState.term(), clusterState.version(), committed);
final ClusterMetadataManifest manifest = new ClusterMetadataManifest(
clusterState.term(),
clusterState.getVersion(),
Expand Down Expand Up @@ -488,22 +491,26 @@ private void setSlowWriteLoggingThreshold(TimeValue slowWriteLoggingThreshold) {
this.slowWriteLoggingThreshold = slowWriteLoggingThreshold;
}

private static String getManifestFileName(long term, long version) {
// 123456789012_test-cluster/cluster-state/dsgYj10Nkso7/manifest/manifest_2147483642_2147483637_456536447
return String.join(DELIMITER, getManifestFileNamePrefix(term, version), RemoteStoreUtils.invertLong(System.currentTimeMillis()));
}

private static String getManifestFileNamePrefix(long term, long version) {
// 123456789012_test-cluster/cluster-state/dsgYj10Nkso7/manifest/manifest_2147483642_2147483637
return String.join(DELIMITER, MANIFEST_PATH_TOKEN, RemoteStoreUtils.invertLong(term), RemoteStoreUtils.invertLong(version));
static String getManifestFileName(long term, long version, boolean committed) {
// 123456789012_test-cluster/cluster-state/dsgYj10Nkso7/manifest/manifest_2147483642_2147483637_1_21473637_456536447
dhwanilpatel marked this conversation as resolved.
Show resolved Hide resolved
return String.join(
DELIMITER,
MANIFEST_PATH_TOKEN,
RemoteStoreUtils.invertLong(term),
RemoteStoreUtils.invertLong(version),
(committed ? "C" : "P"), // C for committed and P for published
dhwanilpatel marked this conversation as resolved.
Show resolved Hide resolved
RemoteStoreUtils.invertLong(MANIFEST_CODEC_VERSION),
RemoteStoreUtils.invertLong(System.currentTimeMillis())
);
}

private static String indexMetadataFileName(IndexMetadata indexMetadata) {
static String indexMetadataFileName(IndexMetadata indexMetadata) {
return String.join(
DELIMITER,
INDEX_METADATA_FILE_PREFIX,
String.valueOf(indexMetadata.getVersion()),
String.valueOf(System.currentTimeMillis())
RemoteStoreUtils.invertLong(indexMetadata.getVersion()),
RemoteStoreUtils.invertLong(INDEX_METADATA_CODEC_VERSION),
RemoteStoreUtils.invertLong(System.currentTimeMillis())
);
}

Expand Down Expand Up @@ -916,8 +923,7 @@ private void deleteClusterMetadata(
if (filesToKeep.contains(uploadedIndexMetadata.getUploadedFilename()) == false) {
staleIndexMetadataPaths.add(
new BlobPath().add(INDEX_PATH_TOKEN).add(uploadedIndexMetadata.getIndexUUID()).buildAsString()
+ uploadedIndexMetadata.getUploadedFilename()
+ ".dat"
+ INDEX_METADATA_FORMAT.blobName(uploadedIndexMetadata.getUploadedFilename())
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.opensearch.core.index.Index;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.gateway.remote.ClusterMetadataManifest.UploadedIndexMetadata;
import org.opensearch.index.remote.RemoteStoreUtils;
import org.opensearch.repositories.FilterRepository;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.repositories.RepositoryMissingException;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.mockito.ArgumentMatchers;

import static org.opensearch.gateway.remote.RemoteClusterStateService.DELIMITER;
import static org.opensearch.gateway.remote.RemoteClusterStateService.INDEX_METADATA_FILE_PREFIX;
import static org.opensearch.gateway.remote.RemoteClusterStateService.MANIFEST_FILE_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
Expand Down Expand Up @@ -673,6 +675,36 @@ public void testDeleteStaleClusterUUIDs() throws IOException {
}
}

public void testFileNames() {
final Index index = new Index("test-index", "index-uuid");
final Settings idxSettings = Settings.builder()
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID())
.build();
final IndexMetadata indexMetadata = new IndexMetadata.Builder(index.getName()).settings(idxSettings)
.numberOfShards(1)
.numberOfReplicas(0)
.build();

String indexMetadataFileName = RemoteClusterStateService.indexMetadataFileName(indexMetadata);
assertThat(indexMetadataFileName.split(DELIMITER).length, is(4));
assertTrue(indexMetadataFileName.contains(INDEX_METADATA_FILE_PREFIX));
assertTrue(indexMetadataFileName.contains(RemoteStoreUtils.invertLong(indexMetadata.getVersion())));
dhwanilpatel marked this conversation as resolved.
Show resolved Hide resolved

int term = randomIntBetween(5, 10);
int version = randomIntBetween(5, 10);
String manifestFileName = RemoteClusterStateService.getManifestFileName(term, version, true);
assertThat(manifestFileName.split(DELIMITER).length, is(6));
assertTrue(manifestFileName.contains(MANIFEST_FILE_PREFIX));
assertTrue(manifestFileName.contains(RemoteStoreUtils.invertLong(term)));
assertTrue(manifestFileName.contains(RemoteStoreUtils.invertLong(version)));
dhwanilpatel marked this conversation as resolved.
Show resolved Hide resolved
assertTrue(manifestFileName.contains("C")); // assertion for committed
assertTrue(manifestFileName.contains(RemoteStoreUtils.invertLong(2))); // assertion for codec version

manifestFileName = RemoteClusterStateService.getManifestFileName(term, version, false);
assertTrue(manifestFileName.contains("P")); // assertion for committed false
}

private void mockObjectsForGettingPreviousClusterUUID(Map<String, String> clusterUUIDsPointers) throws IOException {
final BlobPath blobPath = mock(BlobPath.class);
when((blobStoreRepository.basePath())).thenReturn(blobPath);
Expand Down
Loading