Skip to content

Commit 1ec2ba1

Browse files
committed
Reverted TestGatewayAllocator change
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent 2aa0845 commit 1ec2ba1

File tree

1 file changed

+5
-112
lines changed

1 file changed

+5
-112
lines changed

test/framework/src/main/java/org/opensearch/test/gateway/TestGatewayAllocator.java

Lines changed: 5 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,16 @@
3535
import org.opensearch.cluster.node.DiscoveryNode;
3636
import org.opensearch.cluster.node.DiscoveryNodes;
3737
import org.opensearch.cluster.routing.ShardRouting;
38-
import org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision;
3938
import org.opensearch.cluster.routing.allocation.FailedShard;
4039
import org.opensearch.cluster.routing.allocation.RoutingAllocation;
4140
import org.opensearch.core.index.shard.ShardId;
4241
import org.opensearch.gateway.AsyncShardFetch;
4342
import org.opensearch.gateway.GatewayAllocator;
4443
import org.opensearch.gateway.PrimaryShardAllocator;
45-
import org.opensearch.gateway.PrimaryShardBatchAllocator;
4644
import org.opensearch.gateway.ReplicaShardAllocator;
47-
import org.opensearch.gateway.ReplicaShardBatchAllocator;
48-
import org.opensearch.gateway.TransportNodesListGatewayStartedBatchShards;
4945
import org.opensearch.gateway.TransportNodesListGatewayStartedShards.NodeGatewayStartedShards;
5046
import org.opensearch.indices.replication.checkpoint.ReplicationCheckpoint;
5147
import org.opensearch.indices.store.TransportNodesListShardStoreMetadata.NodeStoreFilesMetadata;
52-
import org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch;
5348

5449
import java.util.Collections;
5550
import java.util.HashMap;
@@ -62,13 +57,13 @@
6257
* A gateway allocator implementation that keeps an in memory list of started shard allocation
6358
* that are used as replies to the, normally async, fetch data requests. The in memory list
6459
* is adapted when shards are started and failed.
65-
*
60+
* <p>
6661
* Nodes leaving and joining the cluster do not change the list of shards the class tracks but
6762
* rather serves as a filter to what is returned by fetch data. Concretely - fetch data will
6863
* only return shards that were started on nodes that are currently part of the cluster.
69-
*
64+
* <p>
7065
* For now only primary shard related data is fetched. Replica request always get an empty response.
71-
*
66+
* <p>
7267
*
7368
* This class is useful to use in unit tests that require the functionality of {@link GatewayAllocator} but do
7469
* not have all the infrastructure required to use it.
@@ -103,52 +98,7 @@ protected AsyncShardFetch.FetchResult<NodeGatewayStartedShards> fetchData(ShardR
10398
)
10499
);
105100

106-
return new AsyncShardFetch.FetchResult<>(foundShards, new HashMap<>() {
107-
{
108-
put(shardId, ignoreNodes);
109-
}
110-
});
111-
}
112-
};
113-
114-
PrimaryShardBatchAllocator primaryBatchShardAllocator = new PrimaryShardBatchAllocator() {
115-
@Override
116-
protected AsyncShardFetch.FetchResult<TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShardsBatch> fetchData(
117-
Set<ShardRouting> shardsEligibleForFetch,
118-
Set<ShardRouting> inEligibleShards,
119-
RoutingAllocation allocation
120-
) {
121-
Map<DiscoveryNode, TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShardsBatch> foundShards = new HashMap<>();
122-
HashMap<ShardId, Set<String>> shardsToIgnoreNodes = new HashMap<>();
123-
for (Map.Entry<String, Map<ShardId, ShardRouting>> entry : knownAllocations.entrySet()) {
124-
String nodeId = entry.getKey();
125-
Map<ShardId, ShardRouting> shardsOnNode = entry.getValue();
126-
HashMap<ShardId, TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShard> adaptedResponse = new HashMap<>();
127-
128-
for (ShardRouting shardRouting : shardsEligibleForFetch) {
129-
ShardId shardId = shardRouting.shardId();
130-
Set<String> ignoreNodes = allocation.getIgnoreNodes(shardId);
131-
132-
if (shardsOnNode.containsKey(shardId) && ignoreNodes.contains(nodeId) == false && currentNodes.nodeExists(nodeId)) {
133-
TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShard nodeShard =
134-
new TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShard(
135-
shardRouting.allocationId().getId(),
136-
shardRouting.primary(),
137-
getReplicationCheckpoint(shardId, nodeId)
138-
);
139-
adaptedResponse.put(shardId, nodeShard);
140-
shardsToIgnoreNodes.put(shardId, ignoreNodes);
141-
}
142-
foundShards.put(
143-
currentNodes.get(nodeId),
144-
new TransportNodesListGatewayStartedBatchShards.NodeGatewayStartedShardsBatch(
145-
currentNodes.get(nodeId),
146-
adaptedResponse
147-
)
148-
);
149-
}
150-
}
151-
return new AsyncShardFetch.FetchResult<>(foundShards, shardsToIgnoreNodes);
101+
return new AsyncShardFetch.FetchResult<>(shardId, foundShards, ignoreNodes);
152102
}
153103
};
154104

@@ -161,28 +111,7 @@ private ReplicationCheckpoint getReplicationCheckpoint(ShardId shardId, String n
161111
protected AsyncShardFetch.FetchResult<NodeStoreFilesMetadata> fetchData(ShardRouting shard, RoutingAllocation allocation) {
162112
// for now, just pretend no node has data
163113
final ShardId shardId = shard.shardId();
164-
return new AsyncShardFetch.FetchResult<>(Collections.emptyMap(), new HashMap<>() {
165-
{
166-
put(shardId, allocation.getIgnoreNodes(shardId));
167-
}
168-
});
169-
}
170-
171-
@Override
172-
protected boolean hasInitiatedFetching(ShardRouting shard) {
173-
return true;
174-
}
175-
};
176-
177-
ReplicaShardBatchAllocator replicaBatchShardAllocator = new ReplicaShardBatchAllocator() {
178-
179-
@Override
180-
protected AsyncShardFetch.FetchResult<TransportNodesListShardStoreMetadataBatch.NodeStoreFilesMetadataBatch> fetchData(
181-
Set<ShardRouting> shardsEligibleForFetch,
182-
Set<ShardRouting> inEligibleShards,
183-
RoutingAllocation allocation
184-
) {
185-
return new AsyncShardFetch.FetchResult<>(Collections.emptyMap(), Collections.emptyMap());
114+
return new AsyncShardFetch.FetchResult<>(shardId, Collections.emptyMap(), allocation.getIgnoreNodes(shardId));
186115
}
187116

188117
@Override
@@ -228,12 +157,6 @@ public void allocateUnassigned(
228157
innerAllocatedUnassigned(allocation, primaryShardAllocator, replicaShardAllocator, shardRouting, unassignedAllocationHandler);
229158
}
230159

231-
@Override
232-
public void allocateUnassignedBatch(RoutingAllocation allocation, boolean primary) {
233-
currentNodes = allocation.nodes();
234-
innerAllocateUnassignedBatch(allocation, primaryBatchShardAllocator, replicaBatchShardAllocator, primary);
235-
}
236-
237160
/**
238161
* manually add a specific shard to the allocations the gateway keeps track of
239162
*/
@@ -248,34 +171,4 @@ public String getReplicationCheckPointKey(ShardId shardId, String nodeName) {
248171
public void addReplicationCheckpoint(ShardId shardId, String nodeName, ReplicationCheckpoint replicationCheckpoint) {
249172
shardIdNodeToReplicationCheckPointMap.putIfAbsent(getReplicationCheckPointKey(shardId, nodeName), replicationCheckpoint);
250173
}
251-
252-
public Set<String> createAndUpdateBatches(RoutingAllocation allocation, boolean primary) {
253-
return super.createAndUpdateBatches(allocation, primary);
254-
}
255-
256-
public void safelyRemoveShardFromBatch(ShardRouting shard) {
257-
super.safelyRemoveShardFromBatch(shard);
258-
}
259-
260-
public void safelyRemoveShardFromBothBatch(ShardRouting shardRouting) {
261-
super.safelyRemoveShardFromBothBatch(shardRouting);
262-
}
263-
264-
public String getBatchId(ShardRouting shard, boolean primary) {
265-
return super.getBatchId(shard, primary);
266-
}
267-
268-
public Map<String, GatewayAllocator.ShardsBatch> getBatchIdToStartedShardBatch() {
269-
return batchIdToStartedShardBatch;
270-
}
271-
272-
public Map<String, GatewayAllocator.ShardsBatch> getBatchIdToStoreShardBatch() {
273-
return batchIdToStoreShardBatch;
274-
}
275-
276-
@Override
277-
public AllocateUnassignedDecision explainUnassignedShardAllocation(ShardRouting unassignedShard, RoutingAllocation routingAllocation) {
278-
setShardAllocators(primaryShardAllocator, replicaShardAllocator, primaryBatchShardAllocator, replicaBatchShardAllocator);
279-
return super.explainUnassignedShardAllocation(unassignedShard, routingAllocation);
280-
}
281174
}

0 commit comments

Comments
 (0)