Search in sources :

Example 66 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRegionAwareEnsemblePlacementPolicy method testNewEnsembleWithThreeRegionsWithDisable.

@Test
public void testNewEnsembleWithThreeRegionsWithDisable() throws Exception {
    FeatureProvider featureProvider = new SettableFeatureProvider("", 0);
    repp.uninitalize();
    repp = new RegionAwareEnsemblePlacementPolicy();
    conf.setProperty(REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME, "disallowBookies");
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, featureProvider, NullStatsLogger.INSTANCE);
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    BookieSocketAddress addr5 = new BookieSocketAddress("127.0.0.6", 3181);
    BookieSocketAddress addr6 = new BookieSocketAddress("127.0.0.7", 3181);
    BookieSocketAddress addr7 = new BookieSocketAddress("127.0.0.8", 3181);
    BookieSocketAddress addr8 = new BookieSocketAddress("127.0.0.9", 3181);
    BookieSocketAddress addr9 = new BookieSocketAddress("127.0.0.10", 3181);
    BookieSocketAddress addr10 = new BookieSocketAddress("127.0.0.11", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/region2/r1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region2/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region3/r4");
    StaticDNSResolver.addNodeToRack(addr5.getHostName(), "/region1/r11");
    StaticDNSResolver.addNodeToRack(addr6.getHostName(), "/region1/r12");
    StaticDNSResolver.addNodeToRack(addr7.getHostName(), "/region2/r13");
    StaticDNSResolver.addNodeToRack(addr8.getHostName(), "/region3/r14");
    StaticDNSResolver.addNodeToRack(addr9.getHostName(), "/region2/r23");
    StaticDNSResolver.addNodeToRack(addr10.getHostName(), "/region1/r24");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    addrs.add(addr5);
    addrs.add(addr6);
    addrs.add(addr7);
    addrs.add(addr8);
    addrs.add(addr9);
    addrs.add(addr10);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ((SettableFeature) featureProvider.scope("region1").getFeature("disallowBookies")).set(true);
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(6, 6, 4, null, new HashSet<BookieSocketAddress>());
        assertEquals(2, getNumRegionsInEnsemble(ensemble));
        assert (ensemble.contains(addr1));
        assert (ensemble.contains(addr3));
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr7));
        assert (ensemble.contains(addr8));
        assert (ensemble.contains(addr9));
        assert (ensemble.size() == 6);
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
    try {
        ((SettableFeature) featureProvider.scope("region2").getFeature("disallowBookies")).set(true);
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(6, 6, 4, null, new HashSet<BookieSocketAddress>());
        fail("Should get not enough bookies exception even there is only one region with insufficient bookies.");
    } catch (BKNotEnoughBookiesException bnebe) {
    // Expected
    }
    try {
        ((SettableFeature) featureProvider.scope("region2").getFeature("disallowBookies")).set(false);
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(6, 6, 4, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.contains(addr1));
        assert (ensemble.contains(addr3));
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr7));
        assert (ensemble.contains(addr8));
        assert (ensemble.contains(addr9));
        assert (ensemble.size() == 6);
        assertEquals(2, getNumRegionsInEnsemble(ensemble));
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) FeatureProvider(org.apache.bookkeeper.feature.FeatureProvider) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 67 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRegionAwareEnsemblePlacementPolicy method testNewEnsembleWithFiveRegions.

@Test
public void testNewEnsembleWithFiveRegions() throws Exception {
    repp.uninitalize();
    repp = new RegionAwareEnsemblePlacementPolicy();
    conf.setProperty(REPP_REGIONS_TO_WRITE, "region1;region2;region3;region4;region5");
    conf.setProperty(REPP_MINIMUM_REGIONS_FOR_DURABILITY, 5);
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    BookieSocketAddress addr1 = new BookieSocketAddress("127.1.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.1.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.1.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.1.0.5", 3181);
    BookieSocketAddress addr5 = new BookieSocketAddress("127.1.0.6", 3181);
    BookieSocketAddress addr6 = new BookieSocketAddress("127.1.0.7", 3181);
    BookieSocketAddress addr7 = new BookieSocketAddress("127.1.0.8", 3181);
    BookieSocketAddress addr8 = new BookieSocketAddress("127.1.0.9", 3181);
    BookieSocketAddress addr9 = new BookieSocketAddress("127.1.0.10", 3181);
    BookieSocketAddress addr10 = new BookieSocketAddress("127.1.0.11", 3181);
    BookieSocketAddress addr11 = new BookieSocketAddress("127.1.0.12", 3181);
    BookieSocketAddress addr12 = new BookieSocketAddress("127.1.0.13", 3181);
    BookieSocketAddress addr13 = new BookieSocketAddress("127.1.0.14", 3181);
    BookieSocketAddress addr14 = new BookieSocketAddress("127.1.0.15", 3181);
    BookieSocketAddress addr15 = new BookieSocketAddress("127.1.0.16", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/region1/r1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region1/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region2/r4");
    StaticDNSResolver.addNodeToRack(addr5.getHostName(), "/region2/r11");
    StaticDNSResolver.addNodeToRack(addr6.getHostName(), "/region2/r12");
    StaticDNSResolver.addNodeToRack(addr7.getHostName(), "/region3/r13");
    StaticDNSResolver.addNodeToRack(addr8.getHostName(), "/region3/r14");
    StaticDNSResolver.addNodeToRack(addr9.getHostName(), "/region3/r23");
    StaticDNSResolver.addNodeToRack(addr10.getHostName(), "/region4/r24");
    StaticDNSResolver.addNodeToRack(addr11.getHostName(), "/region4/r31");
    StaticDNSResolver.addNodeToRack(addr12.getHostName(), "/region4/r32");
    StaticDNSResolver.addNodeToRack(addr13.getHostName(), "/region5/r33");
    StaticDNSResolver.addNodeToRack(addr14.getHostName(), "/region5/r34");
    StaticDNSResolver.addNodeToRack(addr15.getHostName(), "/region5/r35");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    addrs.add(addr5);
    addrs.add(addr6);
    addrs.add(addr7);
    addrs.add(addr8);
    addrs.add(addr9);
    addrs.add(addr10);
    addrs.add(addr11);
    addrs.add(addr12);
    addrs.add(addr13);
    addrs.add(addr14);
    addrs.add(addr15);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(10, 10, 10, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.size() == 10);
        assertEquals(5, getNumRegionsInEnsemble(ensemble));
    } catch (BKNotEnoughBookiesException bnebe) {
        LOG.error("BKNotEnoughBookiesException", bnebe);
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
    try {
        Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
        excludedAddrs.add(addr10);
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(10, 10, 10, null, excludedAddrs);
        assert (ensemble.contains(addr11) && ensemble.contains(addr12));
        assert (ensemble.size() == 10);
        assertEquals(5, getNumRegionsInEnsemble(ensemble));
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 68 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRegionAwareEnsemblePlacementPolicy method testReplaceBookieWithNotEnoughBookies.

@Test
public void testReplaceBookieWithNotEnoughBookies() throws Exception {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region2/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region3/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region4/r4");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    // replace node under r2
    Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
    excludedAddrs.add(addr1);
    excludedAddrs.add(addr3);
    excludedAddrs.add(addr4);
    try {
        repp.replaceBookie(1, 1, 1, null, new HashSet<BookieSocketAddress>(), addr2, excludedAddrs);
        fail("Should throw BKNotEnoughBookiesException when there is not enough bookies");
    } catch (BKNotEnoughBookiesException bnebe) {
    // should throw not enou
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 69 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRegionAwareEnsemblePlacementPolicy method testNewEnsembleWithThreeRegions.

@Test
public void testNewEnsembleWithThreeRegions() throws Exception {
    repp.uninitalize();
    repp = new RegionAwareEnsemblePlacementPolicy();
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    BookieSocketAddress addr5 = new BookieSocketAddress("127.0.0.6", 3181);
    BookieSocketAddress addr6 = new BookieSocketAddress("127.0.0.7", 3181);
    BookieSocketAddress addr7 = new BookieSocketAddress("127.0.0.8", 3181);
    BookieSocketAddress addr8 = new BookieSocketAddress("127.0.0.9", 3181);
    BookieSocketAddress addr9 = new BookieSocketAddress("127.0.0.10", 3181);
    BookieSocketAddress addr10 = new BookieSocketAddress("127.0.0.11", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/region2/r1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region2/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region3/r4");
    StaticDNSResolver.addNodeToRack(addr5.getHostName(), "/region1/r11");
    StaticDNSResolver.addNodeToRack(addr6.getHostName(), "/region1/r12");
    StaticDNSResolver.addNodeToRack(addr7.getHostName(), "/region2/r13");
    StaticDNSResolver.addNodeToRack(addr8.getHostName(), "/region3/r14");
    StaticDNSResolver.addNodeToRack(addr9.getHostName(), "/region2/r23");
    StaticDNSResolver.addNodeToRack(addr10.getHostName(), "/region1/r24");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    addrs.add(addr5);
    addrs.add(addr6);
    addrs.add(addr7);
    addrs.add(addr8);
    addrs.add(addr9);
    addrs.add(addr10);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(6, 6, 4, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr8));
        assert (ensemble.size() == 6);
        assertEquals(3, getNumRegionsInEnsemble(ensemble));
        ensemble = repp.newEnsemble(7, 7, 4, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr8));
        assert (ensemble.size() == 7);
        assertEquals(3, getNumRegionsInEnsemble(ensemble));
        ensemble = repp.newEnsemble(8, 8, 5, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr8));
        assert (ensemble.size() == 8);
        assertEquals(3, getNumRegionsInEnsemble(ensemble));
        ensemble = repp.newEnsemble(9, 9, 5, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.contains(addr4));
        assert (ensemble.contains(addr8));
        assert (ensemble.size() == 9);
        assertEquals(3, getNumRegionsInEnsemble(ensemble));
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 70 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRegionAwareEnsemblePlacementPolicy method testNewEnsembleWithMultipleRegions.

@Test
public void testNewEnsembleWithMultipleRegions() throws Exception {
    repp.uninitalize();
    repp = new RegionAwareEnsemblePlacementPolicy();
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region1/r2");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ArrayList<BookieSocketAddress> ensemble = repp.newEnsemble(3, 2, 2, null, new HashSet<BookieSocketAddress>());
        int numCovered = getNumCoveredRegionsInWriteQuorum(ensemble, 2);
        assertTrue(numCovered >= 1);
        assertTrue(numCovered < 3);
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
    try {
        ArrayList<BookieSocketAddress> ensemble2 = repp.newEnsemble(4, 2, 2, null, new HashSet<BookieSocketAddress>());
        int numCovered = getNumCoveredRegionsInWriteQuorum(ensemble2, 2);
        assertTrue(numCovered >= 1 && numCovered < 3);
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception even there is only one rack.");
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)254 Test (org.junit.Test)140 HashSet (java.util.HashSet)67 CountDownLatch (java.util.concurrent.CountDownLatch)42 ArrayList (java.util.ArrayList)40 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)38 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)37 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)29 HashMap (java.util.HashMap)28 Map (java.util.Map)24 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)23 IOException (java.io.IOException)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 BookieServer (org.apache.bookkeeper.proto.BookieServer)14 WriteCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback)13 Set (java.util.Set)11 ByteBuf (io.netty.buffer.ByteBuf)10 ByteBuffer (java.nio.ByteBuffer)10 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10