Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker]fix npe when invoke replaceBookie. #16239

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,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 @@ -298,6 +298,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