Search in sources :

Example 11 with BookieInfo

use of org.apache.bookkeeper.client.BookieInfoReader.BookieInfo in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method testWeightedPlacementAndNewEnsembleWithoutEnoughBookies.

@Test
public void testWeightedPlacementAndNewEnsembleWithoutEnoughBookies() throws Exception {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.1", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr5 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getSocketAddress().getAddress().getHostAddress(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getSocketAddress().getAddress().getHostAddress(), NetworkTopology.DEFAULT_REGION + "/r2");
    StaticDNSResolver.addNodeToRack(addr3.getSocketAddress().getAddress().getHostAddress(), NetworkTopology.DEFAULT_REGION + "/r2");
    StaticDNSResolver.addNodeToRack(addr4.getSocketAddress().getAddress().getHostAddress(), NetworkTopology.DEFAULT_REGION + "/r3");
    StaticDNSResolver.addNodeToRack(addr5.getSocketAddress().getAddress().getHostAddress(), NetworkTopology.DEFAULT_REGION + "/r3");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    addrs.add(addr5);
    int maxMultiple = 4;
    conf.setDiskWeightBasedPlacementEnabled(true);
    conf.setBookieMaxWeightMultipleForWeightBasedPlacement(maxMultiple);
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    repp.withDefaultRack(NetworkTopology.DEFAULT_REGION_AND_RACK);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    Map<BookieSocketAddress, BookieInfo> bookieInfoMap = new HashMap<BookieSocketAddress, BookieInfo>();
    bookieInfoMap.put(addr1, new BookieInfo(100L, 100L));
    bookieInfoMap.put(addr2, new BookieInfo(100L, 100L));
    bookieInfoMap.put(addr3, new BookieInfo(1000L, 1000L));
    bookieInfoMap.put(addr4, new BookieInfo(100L, 100L));
    bookieInfoMap.put(addr5, new BookieInfo(1000L, 1000L));
    repp.updateBookieInfo(bookieInfoMap);
    ArrayList<BookieSocketAddress> ensemble = new ArrayList<BookieSocketAddress>();
    Set<BookieSocketAddress> excludeList = new HashSet<BookieSocketAddress>();
    try {
        excludeList.add(addr1);
        excludeList.add(addr2);
        excludeList.add(addr3);
        excludeList.add(addr4);
        ensemble = repp.newEnsemble(3, 2, 2, null, excludeList);
        fail("Should throw BKNotEnoughBookiesException when there is not enough bookies" + ensemble);
    } catch (BKNotEnoughBookiesException e) {
    // this is expected
    }
    try {
        ensemble = repp.newEnsemble(1, 1, 1, null, excludeList);
    } catch (BKNotEnoughBookiesException e) {
        fail("Should not throw BKNotEnoughBookiesException when there are enough bookies for the ensemble");
    }
}
Also used : BookieInfo(org.apache.bookkeeper.client.BookieInfoReader.BookieInfo) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with BookieInfo

use of org.apache.bookkeeper.client.BookieInfoReader.BookieInfo in project bookkeeper by apache.

the class TestGetBookieInfoTimeout method testGetBookieInfoTimeout.

@Test
public void testGetBookieInfoTimeout() throws Exception {
    // connect to the bookies and create a ledger
    LedgerHandle writelh = bkc.createLedger(3, 3, digestType, "testPasswd".getBytes());
    String tmp = "Foobar";
    final int numEntries = 10;
    for (int i = 0; i < numEntries; i++) {
        writelh.addEntry(tmp.getBytes());
    }
    // set timeout for getBookieInfo to be 2 secs and cause one of the bookies to go to sleep for 3X that time
    ClientConfiguration cConf = new ClientConfiguration();
    cConf.setGetBookieInfoTimeout(2);
    final BookieSocketAddress bookieToSleep = writelh.getLedgerMetadata().getEnsemble(0).get(0);
    int sleeptime = cConf.getBookieInfoTimeout() * 3;
    CountDownLatch latch = sleepBookie(bookieToSleep, sleeptime);
    latch.await();
    // try to get bookie info from the sleeping bookie. It should fail with timeout error
    BookieSocketAddress addr = new BookieSocketAddress(bookieToSleep.getSocketAddress().getHostString(), bookieToSleep.getPort());
    BookieClient bc = new BookieClient(cConf, eventLoopGroup, executor, scheduler, NullStatsLogger.INSTANCE);
    long flags = BookkeeperProtocol.GetBookieInfoRequest.Flags.FREE_DISK_SPACE_VALUE | BookkeeperProtocol.GetBookieInfoRequest.Flags.TOTAL_DISK_CAPACITY_VALUE;
    class CallbackObj {

        int rc;

        long requested;

        @SuppressWarnings("unused")
        long freeDiskSpace, totalDiskCapacity;

        CountDownLatch latch = new CountDownLatch(1);

        CallbackObj(long requested) {
            this.requested = requested;
            this.rc = 0;
            this.freeDiskSpace = 0L;
            this.totalDiskCapacity = 0L;
        }
    }
    CallbackObj obj = new CallbackObj(flags);
    bc.getBookieInfo(addr, flags, new GetBookieInfoCallback() {

        @Override
        public void getBookieInfoComplete(int rc, BookieInfo bInfo, Object ctx) {
            CallbackObj obj = (CallbackObj) ctx;
            obj.rc = rc;
            if (rc == Code.OK) {
                if ((obj.requested & BookkeeperProtocol.GetBookieInfoRequest.Flags.FREE_DISK_SPACE_VALUE) != 0) {
                    obj.freeDiskSpace = bInfo.getFreeDiskSpace();
                }
                if ((obj.requested & BookkeeperProtocol.GetBookieInfoRequest.Flags.TOTAL_DISK_CAPACITY_VALUE) != 0) {
                    obj.totalDiskCapacity = bInfo.getTotalDiskSpace();
                }
            }
            obj.latch.countDown();
        }
    }, obj);
    obj.latch.await();
    LOG.debug("Return code: " + obj.rc);
    assertTrue("GetBookieInfo failed with unexpected error code: " + obj.rc, obj.rc == Code.TimeoutException);
}
Also used : GetBookieInfoCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GetBookieInfoCallback) BookieClient(org.apache.bookkeeper.proto.BookieClient) BookieInfo(org.apache.bookkeeper.client.BookieInfoReader.BookieInfo) CountDownLatch(java.util.concurrent.CountDownLatch) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Aggregations

BookieInfo (org.apache.bookkeeper.client.BookieInfoReader.BookieInfo)12 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 WeightedObject (org.apache.bookkeeper.client.WeightedRandomSelection.WeightedObject)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)2 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 BookieClient (org.apache.bookkeeper.proto.BookieClient)2 GetBookieInfoCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GetBookieInfoCallback)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Node (org.apache.bookkeeper.net.Node)1