Skip to content

Commit

Permalink
[fix][broker]fix npe when invoke replaceBookie. (#16239)
Browse files Browse the repository at this point in the history
* fix npe when invoke replaceBookie.

* fix npe when invoke replaceBookie.

* fix npe when invoke replaceBookie.

Co-authored-by: nicklixinyang <nicklixinyang@didiglobal.com>
(cherry picked from commit 0eed842)
  • Loading branch information
Nicklee007 authored and codelipenghui committed Jun 28, 2022
1 parent a51196e commit 3048c87
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ private static Pair<Set<String>, Set<String>> getIsolationGroup(
castToString(properties.getOrDefault(SECONDARY_ISOLATION_BOOKIE_GROUPS, ""));
if (!primaryIsolationGroupString.isEmpty()) {
pair.setLeft(new HashSet(Arrays.asList(primaryIsolationGroupString.split(","))));
} else {
pair.setLeft(Collections.emptySet());
}
if (!secondaryIsolationGroupString.isEmpty()) {
pair.setRight(new HashSet(Arrays.asList(secondaryIsolationGroupString.split(","))));
} else {
pair.setRight(Collections.emptySet());
}
}
return pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,39 @@ public void testNoIsolationGroup() throws Exception {
isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

isolationPolicy.newEnsemble(4, 4, 4, Collections.emptyMap(), new HashSet<>());

BookieId bookie1Id = new BookieSocketAddress(BOOKIE1).toBookieId();
BookieId bookie2Id = new BookieSocketAddress(BOOKIE2).toBookieId();
BookieId bookie3Id = new BookieSocketAddress(BOOKIE3).toBookieId();
BookieId bookie4Id = new BookieSocketAddress(BOOKIE4).toBookieId();
// when we set strictBookieAffinityEnabled=true and some namespace not set ISOLATION_BOOKIE_GROUPS there will set "" by default.
Map<String, Object> placementPolicyProperties1 = new HashMap<>();
placementPolicyProperties1.put(
IsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, "");
placementPolicyProperties1.put(
IsolatedBookieEnsemblePlacementPolicy.SECONDARY_ISOLATION_BOOKIE_GROUPS, "");
EnsemblePlacementPolicyConfig policyConfig = new EnsemblePlacementPolicyConfig(
IsolatedBookieEnsemblePlacementPolicy.class,
placementPolicyProperties1
);
Map<String, byte[]> customMetadata1 = new HashMap<>();
customMetadata1.put(EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG, policyConfig.encode());

BookieId replaceBookie1 = isolationPolicy.replaceBookie(3, 3, 3, customMetadata1,
Arrays.asList(bookie1Id,bookie2Id,bookie3Id), bookie3Id, null).getResult();
assertEquals(replaceBookie1, bookie4Id);

// when ISOLATION_BOOKIE_GROUPS miss.
Map<String, Object> placementPolicyProperties2 = new HashMap<>();
EnsemblePlacementPolicyConfig policyConfig2 = new EnsemblePlacementPolicyConfig(
IsolatedBookieEnsemblePlacementPolicy.class,
placementPolicyProperties2
);
Map<String, byte[]> customMetadata2 = new HashMap<>();
customMetadata2.put(EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG, policyConfig.encode());
BookieId replaceBookie2 = isolationPolicy.replaceBookie(3, 3, 3, customMetadata2,
Arrays.asList(bookie1Id,bookie2Id,bookie3Id), bookie3Id, null).getResult();
assertEquals(replaceBookie2, bookie4Id);
}

/**
Expand Down

0 comments on commit 3048c87

Please sign in to comment.