-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add canRemain method to TargetPoolAllocationDecider to move shards fr…
…om (#15010) local to remote pool for hot to warm tiering Signed-off-by: Neetika Singhal <[email protected]>
- Loading branch information
1 parent
a60b668
commit c19cf88
Showing
7 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
server/src/main/java/org/opensearch/action/admin/indices/tiering/TieringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.admin.indices.tiering; | ||
|
||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.cluster.routing.allocation.RoutingAllocation; | ||
import org.opensearch.index.IndexModule; | ||
|
||
/** | ||
* Utility class for tiering operations | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class TieringUtils { | ||
|
||
/** | ||
* Checks if the specified shard is a partial shard by | ||
* checking the INDEX_STORE_LOCALITY_SETTING for its index. | ||
* see {@link #isPartialIndex(IndexMetadata)} | ||
* @param shard ShardRouting object representing the shard | ||
* @param allocation RoutingAllocation object representing the allocation | ||
* @return true if the shard is a partial shard, false otherwise | ||
*/ | ||
public static boolean isPartialShard(ShardRouting shard, RoutingAllocation allocation) { | ||
IndexMetadata indexMetadata = allocation.metadata().getIndexSafe(shard.index()); | ||
return isPartialIndex(indexMetadata); | ||
} | ||
|
||
/** | ||
* Checks if the specified index is a partial index by | ||
* checking the INDEX_STORE_LOCALITY_SETTING for the index. | ||
* | ||
* @param indexMetadata the metadata of the index | ||
* @return true if the index is a partial index, false otherwise | ||
*/ | ||
public static boolean isPartialIndex(final IndexMetadata indexMetadata) { | ||
return IndexModule.DataLocalityType.PARTIAL.name() | ||
.equals(indexMetadata.getSettings().get(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...src/test/java/org/opensearch/cluster/routing/allocation/ShardsTieringAllocationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.routing.allocation; | ||
|
||
import org.opensearch.Version; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.routing.RoutingNode; | ||
import org.opensearch.cluster.routing.RoutingNodes; | ||
import org.opensearch.cluster.routing.RoutingPool; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.index.IndexModule; | ||
import org.opensearch.test.FeatureFlagSetter; | ||
import org.junit.Before; | ||
|
||
import static org.opensearch.cluster.routing.RoutingPool.LOCAL_ONLY; | ||
import static org.opensearch.cluster.routing.RoutingPool.REMOTE_CAPABLE; | ||
import static org.opensearch.cluster.routing.RoutingPool.getIndexPool; | ||
import static org.opensearch.index.IndexModule.INDEX_STORE_LOCALITY_SETTING; | ||
|
||
public class ShardsTieringAllocationTests extends TieringAllocationBaseTestCase { | ||
|
||
@Before | ||
public void setup() { | ||
FeatureFlagSetter.set(FeatureFlags.TIERED_REMOTE_INDEX); | ||
} | ||
|
||
public void testShardsInLocalPool() { | ||
int localOnlyNodes = 5; | ||
int remoteCapableNodes = 3; | ||
int localIndices = 5; | ||
int remoteIndices = 0; | ||
ClusterState clusterState = createInitialCluster(localOnlyNodes, remoteCapableNodes, localIndices, remoteIndices); | ||
AllocationService service = this.createRemoteCapableAllocationService(); | ||
// assign shards to respective nodes | ||
clusterState = allocateShardsAndBalance(clusterState, service); | ||
RoutingNodes routingNodes = clusterState.getRoutingNodes(); | ||
RoutingAllocation allocation = getRoutingAllocation(clusterState, routingNodes); | ||
assertEquals(0, routingNodes.unassigned().size()); | ||
|
||
for (ShardRouting shard : clusterState.getRoutingTable().allShards()) { | ||
assertFalse(shard.unassigned()); | ||
RoutingPool shardPool = RoutingPool.getShardPool(shard, allocation); | ||
assertEquals(LOCAL_ONLY, shardPool); | ||
} | ||
} | ||
|
||
public void testShardsInRemotePool() { | ||
int localOnlyNodes = 7; | ||
int remoteCapableNodes = 3; | ||
int localIndices = 0; | ||
int remoteIndices = 13; | ||
ClusterState clusterState = createInitialCluster(localOnlyNodes, remoteCapableNodes, localIndices, remoteIndices); | ||
AllocationService service = this.createRemoteCapableAllocationService(); | ||
// assign shards to respective nodes | ||
clusterState = allocateShardsAndBalance(clusterState, service); | ||
RoutingNodes routingNodes = clusterState.getRoutingNodes(); | ||
RoutingAllocation allocation = getRoutingAllocation(clusterState, routingNodes); | ||
assertEquals(0, routingNodes.unassigned().size()); | ||
|
||
for (ShardRouting shard : clusterState.getRoutingTable().allShards()) { | ||
assertFalse(shard.unassigned()); | ||
RoutingPool shardPool = RoutingPool.getShardPool(shard, allocation); | ||
assertEquals(REMOTE_CAPABLE, shardPool); | ||
} | ||
} | ||
|
||
public void testShardsWithTiering() { | ||
int localOnlyNodes = 15; | ||
int remoteCapableNodes = 13; | ||
int localIndices = 10; | ||
int remoteIndices = 0; | ||
ClusterState clusterState = createInitialCluster(localOnlyNodes, remoteCapableNodes, localIndices, remoteIndices); | ||
AllocationService service = this.createRemoteCapableAllocationService(); | ||
// assign shards to respective nodes | ||
clusterState = allocateShardsAndBalance(clusterState, service); | ||
// put indices in the hot to warm tiering state | ||
clusterState = updateIndexMetadataForTiering( | ||
clusterState, | ||
localIndices, | ||
IndexModule.TieringState.HOT_TO_WARM.name(), | ||
IndexModule.DataLocalityType.PARTIAL.name() | ||
); | ||
// trigger shard relocation | ||
clusterState = allocateShardsAndBalance(clusterState, service); | ||
RoutingNodes routingNodes = clusterState.getRoutingNodes(); | ||
RoutingAllocation allocation = getRoutingAllocation(clusterState, routingNodes); | ||
assertEquals(0, routingNodes.unassigned().size()); | ||
|
||
for (ShardRouting shard : clusterState.getRoutingTable().allShards()) { | ||
assertFalse(shard.unassigned()); | ||
RoutingNode node = routingNodes.node(shard.currentNodeId()); | ||
RoutingPool nodePool = RoutingPool.getNodePool(node); | ||
RoutingPool shardPool = RoutingPool.getShardPool(shard, allocation); | ||
assertEquals(RoutingPool.REMOTE_CAPABLE, shardPool); | ||
assertEquals(nodePool, shardPool); | ||
} | ||
} | ||
|
||
public void testShardPoolForPartialIndices() { | ||
String index = "test-index"; | ||
IndexMetadata indexMetadata = IndexMetadata.builder(index) | ||
.settings(settings(Version.CURRENT).put(INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.PARTIAL.name())) | ||
.numberOfShards(PRIMARIES) | ||
.numberOfReplicas(REPLICAS) | ||
.build(); | ||
RoutingPool indexPool = getIndexPool(indexMetadata); | ||
assertEquals(REMOTE_CAPABLE, indexPool); | ||
} | ||
|
||
public void testShardPoolForFullIndices() { | ||
String index = "test-index"; | ||
IndexMetadata indexMetadata = IndexMetadata.builder(index) | ||
.settings(settings(Version.CURRENT).put(INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.FULL.name())) | ||
.numberOfShards(PRIMARIES) | ||
.numberOfReplicas(REPLICAS) | ||
.build(); | ||
RoutingPool indexPool = getIndexPool(indexMetadata); | ||
assertEquals(LOCAL_ONLY, indexPool); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...rc/test/java/org/opensearch/cluster/routing/allocation/TieringAllocationBaseTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.routing.allocation; | ||
|
||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.metadata.Metadata; | ||
import org.opensearch.common.SuppressForbidden; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
import static org.opensearch.index.IndexModule.INDEX_STORE_LOCALITY_SETTING; | ||
import static org.opensearch.index.IndexModule.INDEX_TIERING_STATE; | ||
|
||
@SuppressForbidden(reason = "feature flag overrides") | ||
public abstract class TieringAllocationBaseTestCase extends RemoteShardsBalancerBaseTestCase { | ||
|
||
public ClusterState updateIndexMetadataForTiering( | ||
ClusterState clusterState, | ||
int localIndices, | ||
String tieringState, | ||
String dataLocality | ||
) { | ||
Metadata.Builder mb = Metadata.builder(clusterState.metadata()); | ||
for (int i = 0; i < localIndices; i++) { | ||
IndexMetadata indexMetadata = clusterState.metadata().index(getIndexName(i, false)); | ||
Settings settings = indexMetadata.getSettings(); | ||
mb.put( | ||
IndexMetadata.builder(indexMetadata) | ||
.settings( | ||
Settings.builder() | ||
.put(settings) | ||
.put(settings) | ||
.put(INDEX_TIERING_STATE.getKey(), tieringState) | ||
.put(INDEX_STORE_LOCALITY_SETTING.getKey(), dataLocality) | ||
) | ||
); | ||
} | ||
Metadata metadata = mb.build(); | ||
return ClusterState.builder(clusterState).metadata(metadata).build(); | ||
} | ||
} |