Skip to content

Commit

Permalink
add comments and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Jan 22, 2025
1 parent 230b993 commit e52f281
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,26 +264,30 @@ void resolveHost(String hostPort) throws IllegalArgumentException {
return;
}

Set<rpc_address> newSet = new TreeSet<>(Arrays.asList(addrs));
Set<rpc_address> oldSet =
metaList.stream()
.map(ReplicaSession::getAddress)
.collect(Collectors.toCollection(TreeSet::new));
Set<rpc_address> newSet = new TreeSet<>(Arrays.asList(addrs));

// fast path: do nothing if meta list is unchanged.
// Do nothing if meta list is unchanged.
if (newSet.equals(oldSet)) {
return;
}

// removed metas
// Find the meta servers that should be removed.
Set<rpc_address> removedSet = new HashSet<>(oldSet);
removedSet.removeAll(newSet);

// Iterate over the current meta list: once a meta server is found in the removed set,
// it would be removed from the meta list after its session is closed.
Iterator<ReplicaSession> iterator = metaList.iterator();
while (iterator.hasNext()) {
ReplicaSession session = iterator.next();
rpc_address addr = session.getAddress();
if (!removedSet.contains(addr)) {
// This meta server is not found in the removed set, which means it should just be
// retained.
continue;
}

Expand All @@ -292,10 +296,11 @@ void resolveHost(String hostPort) throws IllegalArgumentException {
logger.info("meta server {} was removed", addr);
}

// newly added metas
// Find the meta servers that should be added.
Set<rpc_address> addedSet = new HashSet<>(newSet);
addedSet.removeAll(oldSet);

// Add each new meta servers to the meta list.
for (rpc_address addr : addedSet) {
metaList.add(clusterManager.getReplicaSession(addr));
logger.info("meta server {} was added", addr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void testMetaForwardUnknownPrimary() throws Exception {
FieldUtils.writeField(op, "response", new query_cfg_response(), true);
op.get_response().err = new error_code();
op.get_response().err.errno = error_code.error_types.ERR_FORWARD_TO_OTHERS;
op.get_response().partitions = Collections.singletonList(new partition_configuration[1]);
op.get_response().partitions = Collections.singletonList(new partition_configuration());
op.get_response().partitions.set(0, new partition_configuration());
op.get_response().partitions.get(0).primary = rpc_address.fromIpPort("172.0.0.3:34601");
MetaSession.MetaRequestRound round =
Expand Down

0 comments on commit e52f281

Please sign in to comment.