Search in sources :

Example 61 with BookieSocketAddress

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

the class TestLedgerChecker method testSingleEntryAfterEnsembleChange.

/**
 * Tests that LedgerChecker correctly identifies missing fragments
 * when a single entry is written after an ensemble change.
 * This is important, as the last add confirmed may be less than the
 * first entry id of the final segment.
 */
@Test
public void testSingleEntryAfterEnsembleChange() throws Exception {
    LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
    for (int i = 0; i < 10; i++) {
        lh.addEntry(TEST_LEDGER_ENTRY_DATA);
    }
    ArrayList<BookieSocketAddress> firstEnsemble = lh.getLedgerMetadata().getEnsembles().get(0L);
    DistributionSchedule.WriteSet writeSet = lh.getDistributionSchedule().getWriteSet(lh.getLastAddPushed());
    BookieSocketAddress lastBookieFromEnsemble = firstEnsemble.get(writeSet.get(0));
    LOG.info("Killing " + lastBookieFromEnsemble + " from ensemble=" + firstEnsemble);
    killBookie(lastBookieFromEnsemble);
    startNewBookie();
    lh.addEntry(TEST_LEDGER_ENTRY_DATA);
    writeSet = lh.getDistributionSchedule().getWriteSet(lh.getLastAddPushed());
    lastBookieFromEnsemble = firstEnsemble.get(writeSet.get(1));
    LOG.info("Killing " + lastBookieFromEnsemble + " from ensemble=" + firstEnsemble);
    killBookie(lastBookieFromEnsemble);
    // Open ledger separately for Ledger checker.
    LedgerHandle lh1 = bkc.openLedgerNoRecovery(lh.getId(), BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
    Set<LedgerFragment> result = getUnderReplicatedFragments(lh1);
    assertNotNull("Result shouldn't be null", result);
    assertEquals("There should be 2 fragments. But returned fragments are " + result, 2, result.size());
    for (LedgerFragment lf : result) {
        if (lf.getFirstEntryId() == 0L) {
            assertEquals("There should be 2 failed bookies in first fragment", 2, lf.getBookiesIndexes().size());
        } else {
            assertEquals("There should be 1 failed bookie in second fragment", 1, lf.getBookiesIndexes().size());
        }
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Example 62 with BookieSocketAddress

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

the class TestRackawareEnsemblePlacementPolicyUsingScript method testReplaceBookieWithEnoughBookiesInDifferentRack.

@Test
public void testReplaceBookieWithEnoughBookiesInDifferentRack() throws Exception {
    ignoreTestIfItIsWindowsOS();
    // /1 rack
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.1", 3181);
    // /2 rack
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.2", 3181);
    // /3 rack
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.3", 3181);
    // /4 rack
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.4", 3181);
    // 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);
    BookieSocketAddress replacedBookie = repp.replaceBookie(1, 1, 1, null, new HashSet<>(), addr2, excludedAddrs);
    assertFalse(addr1.equals(replacedBookie));
    assertTrue(addr3.equals(replacedBookie) || addr4.equals(replacedBookie));
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with BookieSocketAddress

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

the class TestRackawareEnsemblePlacementPolicyUsingScript method testNewEnsembleWithEnoughRacks.

@Test
public void testNewEnsembleWithEnoughRacks() throws Exception {
    ignoreTestIfItIsWindowsOS();
    // /1 rack
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.1", 3181);
    // /2 rack
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.2", 3181);
    // /3 rack
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.3", 3181);
    // /4 rack
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.4", 3181);
    // /1 rack
    BookieSocketAddress addr5 = new BookieSocketAddress("127.0.1.1", 3181);
    // /2 rack
    BookieSocketAddress addr6 = new BookieSocketAddress("127.0.1.2", 3181);
    // /3 rack
    BookieSocketAddress addr7 = new BookieSocketAddress("127.0.1.3", 3181);
    // /4 rack
    BookieSocketAddress addr8 = new BookieSocketAddress("127.0.1.4", 3181);
    // 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);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ArrayList<BookieSocketAddress> ensemble1 = repp.newEnsemble(3, 2, 2, null, new HashSet<>());
        assertEquals(3, getNumCoveredWriteQuorums(ensemble1, 2));
        ArrayList<BookieSocketAddress> ensemble2 = repp.newEnsemble(4, 2, 2, null, new HashSet<>());
        assertEquals(4, getNumCoveredWriteQuorums(ensemble2, 2));
    } catch (BKNotEnoughBookiesException bnebe) {
        fail("Should not get not enough bookies exception.");
    }
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 64 with BookieSocketAddress

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

the class TestRackawareEnsemblePlacementPolicyUsingScript method testReplaceBookieWithScriptMappingError2.

/*
     * Test that even in case of script mapping error
     * we are getting default rack that makes sense for the policy.
     * i.e. if all nodes in rack-aware policy use /rack format
     * but one gets node /default-region/default-rack the node addition to topology will fail.
     *
     * This case adds node with default rack, then adds nodes with non-default rack.
     * Almost the same as testReplaceBookieWithScriptMappingError but different order of addition.
     */
@Test
public void testReplaceBookieWithScriptMappingError2() throws Exception {
    ignoreTestIfItIsWindowsOS();
    // error mapping to rack here
    BookieSocketAddress addr0 = new BookieSocketAddress("127.0.0.0", 3181);
    // /1 rack
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.1", 3181);
    // /2 rack
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.2", 3181);
    // Update cluster, add node that maps to default rack first
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr0);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr0);
    addrs.add(addr1);
    addrs.add(addr2);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    // replace node under r2
    Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
    excludedAddrs.add(addr1);
    BookieSocketAddress replacedBookie = repp.replaceBookie(1, 1, 1, null, new HashSet<>(), addr2, excludedAddrs);
    assertFalse(addr1.equals(replacedBookie));
    assertFalse(addr2.equals(replacedBookie));
    assertTrue(addr0.equals(replacedBookie));
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with BookieSocketAddress

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

the class TestRegionAwareEnsemblePlacementPolicy method testNewEnsembleWithEnoughRegions.

@Test
public void testNewEnsembleWithEnoughRegions() 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);
    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);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/default-region/default-rack1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/region2/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/region3/r4");
    StaticDNSResolver.addNodeToRack(addr5.getHostName(), "/default-region/default-rack2");
    StaticDNSResolver.addNodeToRack(addr6.getHostName(), "/region1/r12");
    StaticDNSResolver.addNodeToRack(addr7.getHostName(), "/region2/r13");
    StaticDNSResolver.addNodeToRack(addr8.getHostName(), "/region3/r14");
    // 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);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    try {
        ArrayList<BookieSocketAddress> ensemble1 = repp.newEnsemble(3, 2, 2, null, new HashSet<BookieSocketAddress>());
        assertEquals(3, getNumCoveredRegionsInWriteQuorum(ensemble1, 2));
        ArrayList<BookieSocketAddress> ensemble2 = repp.newEnsemble(4, 2, 2, null, new HashSet<BookieSocketAddress>());
        assertEquals(4, getNumCoveredRegionsInWriteQuorum(ensemble2, 2));
    } 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