Skip to content

Commit

Permalink
[Improve] [Common] Optimize com.alibaba.fluss.cluster.Cluster #Cluste…
Browse files Browse the repository at this point in the history
…r method to remove unnecessary loops alibaba#291
  • Loading branch information
WangS-C committed Dec 31, 2024
1 parent 2700ef5 commit aafcc0e
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,22 @@ public Cluster(
List<BucketLocation> bucketsForTable = entry.getValue();
// Optimise for the common case where all buckets are available.
boolean foundUnavailableBucket = false;
List<BucketLocation> availableBucketsForTable =
new ArrayList<>(bucketsForTable.size());
for (BucketLocation bucketLocation : bucketsForTable) {
if (bucketLocation.getLeader() != null) {
tmpAvailableLocationByBucket.put(
bucketLocation.getTableBucket(), bucketLocation);
availableBucketsForTable.add(bucketLocation);
} else {
foundUnavailableBucket = true;
}
}
if (foundUnavailableBucket) {
List<BucketLocation> availableBucketsForTable =
new ArrayList<>(bucketsForTable.size());
for (BucketLocation loc : bucketsForTable) {
if (loc.getLeader() != null) {
availableBucketsForTable.add(loc);
}
}
tmpAvailableLocationsByPath.put(
physicalTablePath, Collections.unmodifiableList(availableBucketsForTable));
} else {
availableBucketsForTable=null;
tmpAvailableLocationsByPath.put(
physicalTablePath, Collections.unmodifiableList(bucketsForTable));
}
Expand Down

0 comments on commit aafcc0e

Please sign in to comment.