use of org.apache.bookkeeper.net.BookieId in project herddb by diennea.
the class PreferLocalBookiePlacementPolicyTest method testEnsamblePolicySingle.
@Test
public void testEnsamblePolicySingle() throws Exception {
BookieId a = new BookieSocketAddress("a.localhost", 3181).toBookieId();
Set<BookieId> writableBookies = new HashSet<>();
writableBookies.add(a);
registerLocalBookieAddress.invoke(null, a);
try {
Set<BookieId> readOnlyBookies = Collections.emptySet();
PreferLocalBookiePlacementPolicy policy = new PreferLocalBookiePlacementPolicy();
Set<BookieId> deadBookies = policy.onClusterChanged(writableBookies, readOnlyBookies);
assertTrue(deadBookies.isEmpty());
List<BookieId> ensemble = policy.newEnsemble(1, 1, 1, Collections.emptyMap(), Collections.emptySet()).getResult();
System.out.println(ensemble);
assertEquals(1, ensemble.size());
assertEquals(a, ensemble.get(0));
} finally {
unregisterLocalBookieAddress.invoke(null, a);
}
}
use of org.apache.bookkeeper.net.BookieId in project herddb by diennea.
the class PreferLocalBookiePlacementPolicy method newEnsemble.
@Override
public PlacementResult<List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, Set<BookieId> excludeBookies) throws BKNotEnoughBookiesException {
ArrayList<BookieId> newBookies = new ArrayList<>(ensembleSize);
if (ensembleSize <= 0) {
return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
}
List<BookieId> allBookies;
synchronized (this) {
allBookies = new ArrayList<>(knownBookies);
}
BookieId localBookie = null;
for (BookieId bookie : allBookies) {
if (excludeBookies.contains(bookie)) {
continue;
}
if (LocalBookiesRegistry.isLocalBookie(bookie)) {
localBookie = bookie;
break;
}
}
if (localBookie != null) {
boolean ret = allBookies.remove(localBookie);
if (!ret) {
throw new RuntimeException("localBookie not found in list");
}
newBookies.add(localBookie);
--ensembleSize;
if (ensembleSize == 0) {
return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
}
}
Collections.shuffle(allBookies);
for (BookieId bookie : allBookies) {
if (excludeBookies.contains(bookie)) {
continue;
}
newBookies.add(bookie);
--ensembleSize;
if (ensembleSize == 0) {
return PlacementResult.of(newBookies, PlacementPolicyAdherence.MEETS_STRICT);
}
}
throw new BKException.BKNotEnoughBookiesException();
}
Aggregations