-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add serializer to get IndexShardRoutingTable diffs from IndexRoutingT…
…able. Signed-off-by: Shailendra Singh <[email protected]>
- Loading branch information
Shailendra Singh
committed
Jul 10, 2024
1 parent
c0265a2
commit 3589857
Showing
5 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
...c/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.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,2 @@ | ||
package org.opensearch.gateway.remote;public class RemoteRoutingTableServiceIT { | ||
} |
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
66 changes: 66 additions & 0 deletions
66
server/src/main/java/org/opensearch/gateway/remote/routingtable/IndexRoutingTableDiff.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,66 @@ | ||
/* | ||
* 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.gateway.remote.routingtable; | ||
|
||
import org.opensearch.cluster.Diff; | ||
import org.opensearch.cluster.routing.IndexRoutingTable; | ||
import org.opensearch.cluster.routing.IndexShardRoutingTable; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A Service which provides APIs to upload and download routing table from remote store. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
|
||
|
||
public class IndexRoutingTableDiff implements Diff<IndexRoutingTable> { | ||
private final List<IndexShardRoutingTable> indexShardRoutingTables; | ||
|
||
public IndexRoutingTableDiff(List<IndexShardRoutingTable> indexShardRoutingTables) { | ||
this.indexShardRoutingTables = indexShardRoutingTables; | ||
} | ||
|
||
@Override | ||
public IndexRoutingTable apply(IndexRoutingTable part) { | ||
IndexRoutingTable.Builder builder = new IndexRoutingTable.Builder(part.getIndex()); | ||
for (IndexShardRoutingTable shardRoutingTable : part) { | ||
builder.addIndexShard(shardRoutingTable); // Add existing shard to builder | ||
} | ||
|
||
// Apply the diff: update or add the new shard routing tables | ||
for (IndexShardRoutingTable diffShard : indexShardRoutingTables) { | ||
builder.addIndexShard(diffShard); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVInt(indexShardRoutingTables.size()); | ||
for (IndexShardRoutingTable shardRoutingTable : indexShardRoutingTables) { | ||
IndexShardRoutingTable.Builder.writeTo(shardRoutingTable, out); | ||
} | ||
} | ||
|
||
public static IndexRoutingTableDiff readFrom(StreamInput in) throws IOException { | ||
int size = in.readVInt(); | ||
List<IndexShardRoutingTable> indexShardRoutingTables = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
IndexShardRoutingTable shardRoutingTable = IndexShardRoutingTable.Builder.readFrom(in); | ||
indexShardRoutingTables.add(shardRoutingTable); | ||
} | ||
return new IndexRoutingTableDiff(indexShardRoutingTables); | ||
} | ||
} |
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