org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException Java Examples

The following examples show how to use org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreferLocalBookiePlacementPolicy.java    From herddb with Apache License 2.0 5 votes vote down vote up
@Override
public PlacementResult<BookieSocketAddress> replaceBookie(
        int ensembleSize,
        int writeQuorumSize,
        int ackQuorumSize,
        Map<String, byte[]> customMetadata,
        List<BookieSocketAddress> currentEnsemble,
        BookieSocketAddress bookieToReplace,
        Set<BookieSocketAddress> excludeBookies
) throws BKNotEnoughBookiesException {
    excludeBookies.addAll(currentEnsemble);
    PlacementResult<List<BookieSocketAddress>> list = newEnsemble(1, 1, 1, customMetadata, excludeBookies);
    return PlacementResult.of(list.getResult().get(0), PlacementPolicyAdherence.MEETS_STRICT);
}
 
Example #2
Source File: ZkIsolatedBookieEnsemblePlacementPolicy.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public PlacementResult<List<BookieSocketAddress>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize,
        Map<String, byte[]> customMetadata, Set<BookieSocketAddress> excludeBookies)
        throws BKNotEnoughBookiesException {
    Set<BookieSocketAddress> blacklistedBookies = getBlacklistedBookies(ensembleSize);
    if (excludeBookies == null) {
        excludeBookies = new HashSet<BookieSocketAddress>();
    }
    excludeBookies.addAll(blacklistedBookies);
    return super.newEnsemble(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, excludeBookies);
}
 
Example #3
Source File: ZkIsolatedBookieEnsemblePlacementPolicy.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public PlacementResult<BookieSocketAddress> replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize,
        Map<String, byte[]> customMetadata, List<BookieSocketAddress> currentEnsemble,
        BookieSocketAddress bookieToReplace, Set<BookieSocketAddress> excludeBookies)
        throws BKNotEnoughBookiesException {
    Set<BookieSocketAddress> blacklistedBookies = getBlacklistedBookies(ensembleSize);
    if (excludeBookies == null) {
        excludeBookies = new HashSet<BookieSocketAddress>();
    }
    excludeBookies.addAll(blacklistedBookies);
    return super.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, currentEnsemble,
            bookieToReplace, excludeBookies);
}
 
Example #4
Source File: ZkIsolatedBookieEnsemblePlacementPolicyTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoBookieInfo() throws Exception {
    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache("test", localZkc, 30) {
    });
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf, Optional.empty(), timer, SettableFeatureProvider.DISABLE_ALL, NullStatsLogger.INSTANCE);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

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

    String data = "{\"group1\": {\"" + BOOKIE1
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2
            + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4
            + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}";

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    List<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, 2, Collections.emptyMap(), new HashSet<>()).getResult();
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));

    try {
        isolationPolicy.newEnsemble(3, 3, 3, Collections.emptyMap(), new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
        // ok
    }

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
 
Example #5
Source File: ZkIsolatedBookieEnsemblePlacementPolicyTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void testBookieInfoChange() throws Exception {
    Map<String, Map<String, BookieInfo>> bookieMapping = new HashMap<>();
    Map<String, BookieInfo> mainBookieGroup = new HashMap<>();
    Map<String, BookieInfo> secondaryBookieGroup = new HashMap<>();

    mainBookieGroup.put(BOOKIE1, new BookieInfo("rack0", null));
    mainBookieGroup.put(BOOKIE2, new BookieInfo("rack1", null));
    secondaryBookieGroup.put(BOOKIE3, new BookieInfo("rack0", null));
    secondaryBookieGroup.put(BOOKIE4, new BookieInfo("rack2", null));

    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH,
            jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setZkServers("127.0.0.1" + ":" + localZkS.getZookeeperPort());
    bkClientConf.setZkTimeout(1000);
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf, Optional.empty(), timer, SettableFeatureProvider.DISABLE_ALL, NullStatsLogger.INSTANCE);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

    List<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, 2, Collections.emptyMap(), new HashSet<>()).getResult();
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));

    try {
        isolationPolicy.newEnsemble(3, 3, 3, Collections.emptyMap(), new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
        // ok
    }

    mainBookieGroup.put(BOOKIE3, new BookieInfo("rack1", null));
    secondaryBookieGroup.remove(BOOKIE3);
    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);

    localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping),
            -1);

    // wait for the zk to notify and update the mappings
    Thread.sleep(100);

    ensemble = isolationPolicy.newEnsemble(3, 3, 3, Collections.emptyMap(), new HashSet<>()).getResult();
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE3)));

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);

    Thread.sleep(100);

    isolationPolicy.newEnsemble(1, 1, 1, Collections.emptyMap(), new HashSet<>());
}
 
Example #6
Source File: ZkIsolatedBookieEnsemblePlacementPolicyTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecondaryIsolationGroupsBookiesNegative() throws Exception {

    Map<String, Map<String, BookieInfo>> bookieMapping = new HashMap<>();
    Map<String, BookieInfo> defaultBookieGroup = new HashMap<>();
    final String isolatedGroup = "primaryGroup";
    final String secondaryIsolatedGroup = "secondaryGroup";

    defaultBookieGroup.put(BOOKIE1, new BookieInfo("rack0", null));
    defaultBookieGroup.put(BOOKIE2, new BookieInfo("rack1", null));
    defaultBookieGroup.put(BOOKIE3, new BookieInfo("rack1", null));
    defaultBookieGroup.put(BOOKIE4, new BookieInfo("rack1", null));
    defaultBookieGroup.put(BOOKIE5, new BookieInfo("rack1", null));

    Map<String, BookieInfo> primaryIsolatedBookieGroup = new HashMap<>();
    primaryIsolatedBookieGroup.put(BOOKIE1, new BookieInfo("rack1", null));

    bookieMapping.put("default", defaultBookieGroup);
    bookieMapping.put(isolatedGroup, primaryIsolatedBookieGroup);

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH,
            jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache("test", localZkc, 30) {
    });
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolatedGroup);
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.SECONDARY_ISOLATION_BOOKIE_GROUPS,
            secondaryIsolatedGroup);
    isolationPolicy.initialize(bkClientConf, Optional.empty(), timer, SettableFeatureProvider.DISABLE_ALL,
            NullStatsLogger.INSTANCE);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

    try {
        List<BookieSocketAddress> ensemble = isolationPolicy
                .newEnsemble(3, 3, 2, Collections.emptyMap(), new HashSet<>()).getResult();
        Assert.fail("Should have thrown BKNotEnoughBookiesException");
    } catch (BKNotEnoughBookiesException ne) {
        // Ok..
    }

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}