Skip to content

Commit

Permalink
fix: remove redundant code
Browse files Browse the repository at this point in the history
Signed-off-by: chyezh <[email protected]>
  • Loading branch information
chyezh committed Apr 15, 2024
1 parent 0016e15 commit a3db93a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
6 changes: 6 additions & 0 deletions examples/main/java/io/milvus/ResourceGroupExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ private static void printResourceGroupInfo() throws Exception {
}

public static void main(String[] args) throws Exception {
// It's a demo to show how to use resource group management.
// It create a database-level-resource-group-control (single replica)
// management.
// Declarative resource group API can also achieve
// replica-level-resource-group-control (multi-replica) management.

printResourceGroupInfo();
// Initialize the cluster with 1 resource group
// default_rg: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ResourceGroupInfo {
private Set<String> partialDatabases; // databases belong to this resource group partially, some collection is in
// other resource group.
private Set<NodeInfo> nodes; // actual query node in this resource group.
private Integer requestsNodeNum; // max query node in this resource group.

private ResourceGroupInfo(@NonNull Builder builder) {
this.resourceGroupName = builder.resourceGroupName;
Expand All @@ -32,7 +31,6 @@ private ResourceGroupInfo(@NonNull Builder builder) {
if (this.nodes == null) {
this.nodes = new HashSet<NodeInfo>();
}
this.requestsNodeNum = builder.requestsNodeNum;
}

public static Builder newBuilder() {
Expand All @@ -45,7 +43,6 @@ public static final class Builder {
private Set<String> fullDatabases;
private Set<String> partialDatabases;
private Set<NodeInfo> nodes; // actual query node in this resource group.
private Integer requestsNodeNum;

public Builder withResourceGroupName(@NonNull String resourceGroupName) {
this.resourceGroupName = resourceGroupName;
Expand Down Expand Up @@ -76,11 +73,6 @@ public Builder addAvailableNode(@NonNull NodeInfo node) {
return this;
}

public Builder withRequestsNodeNum(@NonNull Integer requestsNodeNum) {
this.requestsNodeNum = requestsNodeNum;
return this;
}

public Builder withConfig(@NonNull ResourceGroupConfig resourceGroupConfig) {
this.resourceGroupConfig = resourceGroupConfig;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public Map<String, ResourceGroupInfo> listResourceGroups() throws Exception {

ResourceGroupInfo.Builder builder = ResourceGroupInfo.newBuilder()
.withResourceGroupName(resourceGroupName)
.withRequestsNodeNum(resourceGroupInfo.getResourceGroup().getConfig().getRequests().getNodeNum())
.withConfig(new ResourceGroupConfig(resourceGroupInfo.getResourceGroup().getConfig()));

resourceGroupInfo.getResourceGroup().getNodesList().forEach(node -> {
builder.addAvailableNode(NodeInfo.newBuilder()
.withNodeId(node.getNodeId())
Expand Down Expand Up @@ -132,7 +131,7 @@ public void initializeCluster(Integer defaultResourceGroupNodeNum) throws Except
.withRequests(new ResourceGroupLimit(RECYCLE_RG_REQUEST_NODE_NUM))
.withLimits(new ResourceGroupLimit(RECYCLE_RG_LIMIT_NODE_NUM))
.build())
.build());
.build());
unwrap(resp);
this.scaleResourceGroupTo(DEFAULT_RG, defaultResourceGroupNodeNum);
}
Expand Down Expand Up @@ -231,10 +230,8 @@ public void transferDataBaseToResourceGroup(String dbName, String resourceGroupN
* @throws Exception
*/
private String getCollectionResourceGroupName(String dbName, String collection) throws Exception {
R<GetLoadStateResponse> loaded = client.getLoadState(GetLoadStateParam.newBuilder().
withDatabaseName(dbName).
withCollectionName(collection).
build());
R<GetLoadStateResponse> loaded = client.getLoadState(
GetLoadStateParam.newBuilder().withDatabaseName(dbName).withCollectionName(collection).build());
GetLoadStateResponse loadedState = unwrap(loaded);

if (loadedState.getState() != LoadState.LoadStateLoaded) {
Expand All @@ -245,12 +242,16 @@ private String getCollectionResourceGroupName(String dbName, String collection)

// Get the current resource group of the collection.
R<GetReplicasResponse> replicaResp = client
.getReplicas(GetReplicasParam.newBuilder().withCollectionName(collection).withDatabaseName(dbName).build());
.getReplicas(
GetReplicasParam.newBuilder().withCollectionName(collection).withDatabaseName(dbName).build());
GetReplicasResponse replicas = unwrap(replicaResp);

if (replicas.getReplicasCount() > 1) {
// Multi replica is now supported now.
throw new RuntimeException(String.format("Replica number {} is greater than 1, did not support now",
// Multi replica is supported with multiple resource group.
// But current example only support single replica, so throw exception here.
// You can modify the code to support multi replicas.
throw new RuntimeException(String.format(
"Replica number {} is greater than 1, did not support now in current example, you can modify the code to support it.",
replicas.getReplicasCount()));
}
if (replicas.getReplicasCount() == 0) {
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/io/milvus/common/resourcegroup/ResourceGroup.java

This file was deleted.

0 comments on commit a3db93a

Please sign in to comment.