Skip to content

Commit b07035e

Browse files
committed
upload translog ckp file as object metadata to translog tlog file
Signed-off-by: Sandeep Kumawat <2025sandeepkumawat@gmail.com>
1 parent c65f9eb commit b07035e

23 files changed

+305
-177
lines changed

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@
8989
import org.opensearch.index.mapper.MapperService;
9090
import org.opensearch.index.mapper.MapperService.MergeReason;
9191
import org.opensearch.index.query.QueryShardContext;
92+
import org.opensearch.index.remote.RemoteStoreCustomMetadataResolver;
93+
import org.opensearch.index.remote.RemoteStoreEnums;
9294
import org.opensearch.index.remote.RemoteStoreEnums.PathHashAlgorithm;
9395
import org.opensearch.index.remote.RemoteStoreEnums.PathType;
9496
import org.opensearch.index.remote.RemoteStorePathStrategy;
95-
import org.opensearch.index.remote.RemoteStorePathStrategyResolver;
9697
import org.opensearch.index.shard.IndexSettingProvider;
9798
import org.opensearch.index.translog.Translog;
9899
import org.opensearch.indices.IndexCreationException;
@@ -177,7 +178,7 @@ public class MetadataCreateIndexService {
177178
private AwarenessReplicaBalance awarenessReplicaBalance;
178179

179180
@Nullable
180-
private final RemoteStorePathStrategyResolver remoteStorePathStrategyResolver;
181+
private final RemoteStoreCustomMetadataResolver remoteStoreCustomMetadataResolver;
181182

182183
public MetadataCreateIndexService(
183184
final Settings settings,
@@ -212,8 +213,8 @@ public MetadataCreateIndexService(
212213
// Task is onboarded for throttling, it will get retried from associated TransportClusterManagerNodeAction.
213214
createIndexTaskKey = clusterService.registerClusterManagerTask(ClusterManagerTaskKeys.CREATE_INDEX_KEY, true);
214215
Supplier<Version> minNodeVersionSupplier = () -> clusterService.state().nodes().getMinNodeVersion();
215-
remoteStorePathStrategyResolver = isRemoteDataAttributePresent(settings)
216-
? new RemoteStorePathStrategyResolver(remoteStoreSettings, minNodeVersionSupplier)
216+
remoteStoreCustomMetadataResolver = isRemoteDataAttributePresent(settings)
217+
? new RemoteStoreCustomMetadataResolver(remoteStoreSettings, minNodeVersionSupplier)
217218
: null;
218219
}
219220

@@ -562,7 +563,7 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
562563
tmpImdBuilder.setRoutingNumShards(routingNumShards);
563564
tmpImdBuilder.settings(indexSettings);
564565
tmpImdBuilder.system(isSystem);
565-
addRemoteStorePathStrategyInCustomData(tmpImdBuilder, true);
566+
addRemoteStoreCustomMetadata(tmpImdBuilder, true);
566567

567568
// Set up everything, now locally create the index to see that things are ok, and apply
568569
IndexMetadata tempMetadata = tmpImdBuilder.build();
@@ -572,23 +573,28 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
572573
}
573574

574575
/**
575-
* Adds the remote store path type information in custom data of index metadata.
576+
* Adds the 1) remote store path type 2) ckp as translog metadata information in custom data of index metadata.
576577
*
577578
* @param tmpImdBuilder index metadata builder.
578579
* @param assertNullOldType flag to verify that the old remote store path type is null
579580
*/
580-
public void addRemoteStorePathStrategyInCustomData(IndexMetadata.Builder tmpImdBuilder, boolean assertNullOldType) {
581-
if (remoteStorePathStrategyResolver == null) {
581+
public void addRemoteStoreCustomMetadata(IndexMetadata.Builder tmpImdBuilder, boolean assertNullOldType) {
582+
if (remoteStoreCustomMetadataResolver == null) {
582583
return;
583584
}
584585
// It is possible that remote custom data exists already. In such cases, we need to only update the path type
585586
// in the remote store custom data map.
586587
Map<String, String> existingCustomData = tmpImdBuilder.removeCustom(IndexMetadata.REMOTE_STORE_CUSTOM_KEY);
587588
assert assertNullOldType == false || Objects.isNull(existingCustomData);
588589

589-
// Determine the path type for use using the remoteStorePathResolver.
590-
RemoteStorePathStrategy newPathStrategy = remoteStorePathStrategyResolver.get();
591590
Map<String, String> remoteCustomData = new HashMap<>();
591+
592+
// Determine if the ckp would be stored as translog metadata
593+
boolean isCkpAsTranslogMetadata = remoteStoreCustomMetadataResolver.isCkpAsTranslogMetadata();
594+
remoteCustomData.put(RemoteStoreEnums.CKP_AS_METADATA, Boolean.toString(isCkpAsTranslogMetadata));
595+
596+
// Determine the path type for use using the remoteStorePathResolver.
597+
RemoteStorePathStrategy newPathStrategy = remoteStoreCustomMetadataResolver.getPathStrategy();
592598
remoteCustomData.put(PathType.NAME, newPathStrategy.getType().name());
593599
if (Objects.nonNull(newPathStrategy.getHashAlgorithm())) {
594600
remoteCustomData.put(PathHashAlgorithm.NAME, newPathStrategy.getHashAlgorithm().name());

server/src/main/java/org/opensearch/cluster/routing/allocation/IndexMetadataUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public Metadata applyChanges(Metadata oldMetadata, RoutingTable newRoutingTable,
176176
oldMetadata.settings(),
177177
logger
178178
);
179-
migrationImdUpdater.maybeUpdateRemoteStorePathStrategy(indexMetadataBuilder, index.getName());
179+
migrationImdUpdater.maybeUpdateRemoteStoreCustomMetadata(indexMetadataBuilder, index.getName());
180180
migrationImdUpdater.maybeAddRemoteIndexSettings(indexMetadataBuilder, index.getName());
181181
}
182182
}

server/src/main/java/org/opensearch/common/blobstore/BlobStore.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ default Map<Metric, Map<String, Long>> extendedStats() {
7171
*/
7272
default void reload(RepositoryMetadata repositoryMetadata) {}
7373

74+
/**
75+
* Returns a boolean indicating if blobStore support object metadata upload
76+
*/
77+
default boolean isBlobMetadataSupported() {
78+
return false;
79+
}
80+
7481
/**
7582
* Metrics for BlobStore interactions
7683
*/

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ public void apply(Settings value, Settings current, Settings previous) {
739739
RemoteStoreSettings.CLUSTER_REMOTE_TRANSLOG_TRANSFER_TIMEOUT_SETTING,
740740
RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING,
741741
RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_HASH_ALGORITHM_SETTING,
742-
RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS
742+
RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS,
743+
RemoteStoreSettings.CLUSTER_REMOTE_STORE_TRANSLOG_CKP_AS_METADATA
743744
)
744745
)
745746
);

server/src/main/java/org/opensearch/index/IndexSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ public static IndexMergePolicy fromString(String text) {
763763
private final boolean widenIndexSortType;
764764
private final boolean assignedOnRemoteNode;
765765
private final RemoteStorePathStrategy remoteStorePathStrategy;
766+
private final boolean ckpAsTranslogMetadata;
766767

767768
/**
768769
* The maximum age of a retention lease before it is considered expired.
@@ -989,6 +990,8 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
989990
assignedOnRemoteNode = RemoteStoreNodeAttribute.isRemoteDataAttributePresent(this.getNodeSettings());
990991
remoteStorePathStrategy = RemoteStoreUtils.determineRemoteStorePathStrategy(indexMetadata);
991992

993+
ckpAsTranslogMetadata = RemoteStoreUtils.determineCkpAsTranslogMetadata(indexMetadata);
994+
992995
setEnableFuzzySetForDocId(scopedSettings.get(INDEX_DOC_ID_FUZZY_SET_ENABLED_SETTING));
993996
setDocIdFuzzySetFalsePositiveProbability(scopedSettings.get(INDEX_DOC_ID_FUZZY_SET_FALSE_POSITIVE_PROBABILITY_SETTING));
994997

@@ -1911,4 +1914,8 @@ public void setDocIdFuzzySetFalsePositiveProbability(double docIdFuzzySetFalsePo
19111914
public RemoteStorePathStrategy getRemoteStorePathStrategy() {
19121915
return remoteStorePathStrategy;
19131916
}
1917+
1918+
public boolean isCkpAsTranslogMetadata() {
1919+
return ckpAsTranslogMetadata;
1920+
}
19141921
}

server/src/main/java/org/opensearch/index/remote/RemoteMigrationIndexMetadataUpdater.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED;
2929
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY;
3030
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
31-
import static org.opensearch.index.remote.RemoteStoreUtils.determineRemoteStorePathStrategyDuringMigration;
31+
import static org.opensearch.index.remote.RemoteStoreUtils.determineRemoteStoreCustomMetadataDuringMigration;
3232
import static org.opensearch.index.remote.RemoteStoreUtils.getRemoteStoreRepoName;
3333
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
3434
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
@@ -118,7 +118,7 @@ private boolean needsRemoteIndexSettingsUpdate(
118118
}
119119

120120
/**
121-
* Updates the remote store path strategy metadata for the index when it is migrating to remote.
121+
* Updates the remote store custom metadata for the index when it is migrating to remote.
122122
* This is run during state change of each shard copy when the cluster is in `MIXED` mode and the direction of migration is `REMOTE_STORE`
123123
* Should not interfere with docrep functionality even if the index is in docrep nodes since this metadata
124124
* is not used anywhere in the docrep flow
@@ -127,20 +127,20 @@ private boolean needsRemoteIndexSettingsUpdate(
127127
* @param indexMetadataBuilder Mutated {@link IndexMetadata.Builder} having the previous state updates
128128
* @param index index name
129129
*/
130-
public void maybeUpdateRemoteStorePathStrategy(IndexMetadata.Builder indexMetadataBuilder, String index) {
131-
if (indexHasRemotePathMetadata(indexMetadata) == false) {
132-
logger.info("Adding remote store path strategy for index [{}] during migration", index);
130+
public void maybeUpdateRemoteStoreCustomMetadata(IndexMetadata.Builder indexMetadataBuilder, String index) {
131+
if (indexHasRemoteCustomMetadata(indexMetadata) == false) {
132+
logger.info("Adding remote store custom data for index [{}] during migration", index);
133133
indexMetadataBuilder.putCustom(
134134
REMOTE_STORE_CUSTOM_KEY,
135-
determineRemoteStorePathStrategyDuringMigration(clusterSettings, discoveryNodes)
135+
determineRemoteStoreCustomMetadataDuringMigration(clusterSettings, discoveryNodes)
136136
);
137137
} else {
138-
logger.debug("Index {} already has remote store path strategy", index);
138+
logger.debug("Index {} already has remote store custom data", index);
139139
}
140140
}
141141

142142
public static boolean indexHasAllRemoteStoreRelatedMetadata(IndexMetadata indexMetadata) {
143-
return indexHasRemoteStoreSettings(indexMetadata.getSettings()) && indexHasRemotePathMetadata(indexMetadata);
143+
return indexHasRemoteStoreSettings(indexMetadata.getSettings()) && indexHasRemoteCustomMetadata(indexMetadata);
144144
}
145145

146146
/**
@@ -167,9 +167,11 @@ public static boolean indexHasRemoteStoreSettings(Settings indexSettings) {
167167
* @param indexMetadata Current index metadata
168168
* @return <code>true</code> if all above conditions match. <code>false</code> otherwise
169169
*/
170-
public static boolean indexHasRemotePathMetadata(IndexMetadata indexMetadata) {
170+
public static boolean indexHasRemoteCustomMetadata(IndexMetadata indexMetadata) {
171171
Map<String, String> customMetadata = indexMetadata.getCustomData(REMOTE_STORE_CUSTOM_KEY);
172-
return Objects.nonNull(customMetadata) && Objects.nonNull(customMetadata.get(PathType.NAME));
172+
return Objects.nonNull(customMetadata)
173+
&& Objects.nonNull(customMetadata.get(PathType.NAME))
174+
&& Objects.nonNull(customMetadata.get(RemoteStoreEnums.CKP_AS_METADATA));
173175
}
174176

175177
public static void updateRemoteStoreSettings(Settings.Builder settingsBuilder, String segmentRepository, String translogRepository) {

server/src/main/java/org/opensearch/index/remote/RemoteStorePathStrategyResolver.java renamed to server/src/main/java/org/opensearch/index/remote/RemoteStoreCustomMetadataResolver.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
* @opensearch.internal
2323
*/
2424
@ExperimentalApi
25-
public class RemoteStorePathStrategyResolver {
25+
public class RemoteStoreCustomMetadataResolver {
2626

2727
private final RemoteStoreSettings remoteStoreSettings;
2828
private final Supplier<Version> minNodeVersionSupplier;
2929

30-
public RemoteStorePathStrategyResolver(RemoteStoreSettings remoteStoreSettings, Supplier<Version> minNodeVersionSupplier) {
30+
public RemoteStoreCustomMetadataResolver(RemoteStoreSettings remoteStoreSettings, Supplier<Version> minNodeVersionSupplier) {
3131
this.remoteStoreSettings = remoteStoreSettings;
3232
this.minNodeVersionSupplier = minNodeVersionSupplier;
3333
}
3434

35-
public RemoteStorePathStrategy get() {
35+
public RemoteStorePathStrategy getPathStrategy() {
3636
PathType pathType;
3737
PathHashAlgorithm pathHashAlgorithm;
3838
// Min node version check ensures that we are enabling the new prefix type only when all the nodes understand it.
@@ -41,4 +41,9 @@ public RemoteStorePathStrategy get() {
4141
pathHashAlgorithm = pathType == PathType.FIXED ? null : remoteStoreSettings.getPathHashAlgorithm();
4242
return new RemoteStorePathStrategy(pathType, pathHashAlgorithm);
4343
}
44+
45+
public boolean isCkpAsTranslogMetadata() {
46+
return Version.CURRENT.compareTo(minNodeVersionSupplier.get()) <= 0 && remoteStoreSettings.isCkpAsTranslogMetadata();
47+
}
48+
4449
}

server/src/main/java/org/opensearch/index/remote/RemoteStoreEnums.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
@ExperimentalApi
3737
public class RemoteStoreEnums {
3838

39+
public static final String CKP_AS_METADATA = "ckp-as-metadata";
40+
3941
/**
4042
* Categories of the data in Remote store.
4143
*/

server/src/main/java/org/opensearch/index/remote/RemoteStoreUtils.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_HASH_ALGORITHM_SETTING;
3434
import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING;
35+
import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_TRANSLOG_CKP_AS_METADATA;
3536

3637
/**
3738
* Utils for remote store
@@ -181,25 +182,42 @@ public static RemoteStorePathStrategy determineRemoteStorePathStrategy(IndexMeta
181182
return new RemoteStorePathStrategy(RemoteStoreEnums.PathType.FIXED);
182183
}
183184

185+
/**
186+
* Determines whether translog ckp upload as metadata allowed or not
187+
*/
188+
public static boolean determineCkpAsTranslogMetadata(IndexMetadata indexMetadata) {
189+
Map<String, String> remoteCustomData = indexMetadata.getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY);
190+
assert remoteCustomData == null || remoteCustomData.containsKey(RemoteStoreEnums.CKP_AS_METADATA);
191+
if (remoteCustomData != null && remoteCustomData.containsKey(RemoteStoreEnums.CKP_AS_METADATA)) {
192+
return Boolean.parseBoolean(remoteCustomData.get(RemoteStoreEnums.CKP_AS_METADATA));
193+
}
194+
return false;
195+
}
196+
184197
/**
185198
* Generates the remote store path type information to be added to custom data of index metadata during migration
186199
*
187200
* @param clusterSettings Current Cluster settings from {@link ClusterState}
188-
* @param discoveryNodes Current {@link DiscoveryNodes} from the cluster state
201+
* @param discoveryNodes Current {@link DiscoveryNodes} from the cluster state
189202
* @return {@link Map} to be added as custom data in index metadata
190203
*/
191-
public static Map<String, String> determineRemoteStorePathStrategyDuringMigration(
204+
public static Map<String, String> determineRemoteStoreCustomMetadataDuringMigration(
192205
Settings clusterSettings,
193206
DiscoveryNodes discoveryNodes
194207
) {
208+
Map<String, String> remoteCustomData = new HashMap<>();
195209
Version minNodeVersion = discoveryNodes.getMinNodeVersion();
210+
211+
boolean ckpAsMetadata = Version.CURRENT.compareTo(minNodeVersion) <= 0
212+
&& CLUSTER_REMOTE_STORE_TRANSLOG_CKP_AS_METADATA.get(clusterSettings);
213+
remoteCustomData.put(RemoteStoreEnums.CKP_AS_METADATA, Boolean.toString(ckpAsMetadata));
214+
196215
RemoteStoreEnums.PathType pathType = Version.CURRENT.compareTo(minNodeVersion) <= 0
197216
? CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.get(clusterSettings)
198217
: RemoteStoreEnums.PathType.FIXED;
199218
RemoteStoreEnums.PathHashAlgorithm pathHashAlgorithm = pathType == RemoteStoreEnums.PathType.FIXED
200219
? null
201220
: CLUSTER_REMOTE_STORE_PATH_HASH_ALGORITHM_SETTING.get(clusterSettings);
202-
Map<String, String> remoteCustomData = new HashMap<>();
203221
remoteCustomData.put(RemoteStoreEnums.PathType.NAME, pathType.name());
204222
if (Objects.nonNull(pathHashAlgorithm)) {
205223
remoteCustomData.put(RemoteStoreEnums.PathHashAlgorithm.NAME, pathHashAlgorithm.name());

server/src/main/java/org/opensearch/index/shard/IndexShard.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,14 @@ public void deleteTranslogFilesFromRemoteTranslog() throws IOException {
49764976
TranslogFactory translogFactory = translogFactorySupplier.apply(indexSettings, shardRouting);
49774977
assert translogFactory instanceof RemoteBlobStoreInternalTranslogFactory;
49784978
Repository repository = ((RemoteBlobStoreInternalTranslogFactory) translogFactory).getRepository();
4979-
RemoteFsTranslog.cleanup(repository, shardId, getThreadPool(), indexSettings.getRemoteStorePathStrategy(), remoteStoreSettings);
4979+
RemoteFsTranslog.cleanup(
4980+
repository,
4981+
shardId,
4982+
getThreadPool(),
4983+
indexSettings.getRemoteStorePathStrategy(),
4984+
remoteStoreSettings,
4985+
indexSettings().isCkpAsTranslogMetadata()
4986+
);
49804987
}
49814988

49824989
/*
@@ -5001,7 +5008,8 @@ public void syncTranslogFilesFromRemoteTranslog() throws IOException {
50015008
indexSettings.getRemoteStorePathStrategy(),
50025009
remoteStoreSettings,
50035010
logger,
5004-
shouldSeedRemoteStore()
5011+
shouldSeedRemoteStore(),
5012+
indexSettings().isCkpAsTranslogMetadata()
50055013
);
50065014
}
50075015

0 commit comments

Comments
 (0)