Search in sources :

Example 6 with SettableFeatureProvider

use of org.apache.bookkeeper.feature.SettableFeatureProvider in project bookkeeper by apache.

the class TestDisableEnsembleChange method disableEnsembleChangeTest.

void disableEnsembleChangeTest(boolean startNewBookie) throws Exception {
    ClientConfiguration conf = new ClientConfiguration();
    conf.setZkServers(zkUtil.getZooKeeperConnectString());
    conf.setDelayEnsembleChange(false).setDisableEnsembleChangeFeatureName(FEATURE_DISABLE_ENSEMBLE_CHANGE);
    SettableFeatureProvider featureProvider = new SettableFeatureProvider("test", 0);
    BookKeeper bkc = BookKeeper.forConfig(conf).featureProvider(featureProvider).build();
    SettableFeature disableEnsembleChangeFeature = featureProvider.getFeature(FEATURE_DISABLE_ENSEMBLE_CHANGE);
    disableEnsembleChangeFeature.set(true);
    final byte[] password = new byte[0];
    final LedgerHandle lh = bkc.createLedger(4, 3, 2, BookKeeper.DigestType.CRC32, password);
    final AtomicBoolean finished = new AtomicBoolean(false);
    final AtomicBoolean failTest = new AtomicBoolean(false);
    final byte[] entry = "test-disable-ensemble-change".getBytes(UTF_8);
    assertEquals(1, lh.getLedgerMetadata().getEnsembles().size());
    ArrayList<BookieSocketAddress> ensembleBeforeFailure = new ArrayList<>(lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue());
    final RateLimiter rateLimiter = RateLimiter.create(10);
    Thread addThread = new Thread() {

        @Override
        public void run() {
            try {
                while (!finished.get()) {
                    rateLimiter.acquire();
                    lh.addEntry(entry);
                }
            } catch (Exception e) {
                logger.error("Exception on adding entry : ", e);
                failTest.set(true);
            }
        }
    };
    addThread.start();
    Thread.sleep(2000);
    killBookie(0);
    Thread.sleep(2000);
    finished.set(true);
    addThread.join();
    assertFalse("Should not fail adding entries facing one bookie failure when disable ensemble change", failTest.get());
    // check the ensemble after failure
    assertEquals("No new ensemble should be added when disable ensemble change.", 1, lh.getLedgerMetadata().getEnsembles().size());
    ArrayList<BookieSocketAddress> ensembleAfterFailure = new ArrayList<>(lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue());
    assertArrayEquals(ensembleBeforeFailure.toArray(new BookieSocketAddress[ensembleBeforeFailure.size()]), ensembleAfterFailure.toArray(new BookieSocketAddress[ensembleAfterFailure.size()]));
    // enable ensemble change
    disableEnsembleChangeFeature.set(false);
    if (startNewBookie) {
        startNewBookie();
    }
    // reset add thread
    finished.set(false);
    final CountDownLatch failLatch = new CountDownLatch(1);
    addThread = new Thread() {

        @Override
        public void run() {
            try {
                while (!finished.get()) {
                    lh.addEntry(entry);
                }
            } catch (Exception e) {
                logger.error("Exception on adding entry : ", e);
                failLatch.countDown();
                failTest.set(true);
            }
        }
    };
    addThread.start();
    failLatch.await(4000, TimeUnit.MILLISECONDS);
    finished.set(true);
    addThread.join();
    if (startNewBookie) {
        assertFalse("Should not fail adding entries when enable ensemble change again.", failTest.get());
        assertFalse("Ledger should be closed when enable ensemble change again.", lh.getLedgerMetadata().isClosed());
        assertEquals("New ensemble should be added when enable ensemble change again.", 2, lh.getLedgerMetadata().getEnsembles().size());
    } else {
        assertTrue("Should fail adding entries when enable ensemble change again.", failTest.get());
        assertTrue("Ledger should be closed when enable ensemble change again.", lh.getLedgerMetadata().isClosed());
    }
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) RateLimiter(com.google.common.util.concurrent.RateLimiter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 7 with SettableFeatureProvider

use of org.apache.bookkeeper.feature.SettableFeatureProvider in project bookkeeper by apache.

the class TestDisableEnsembleChange method testRetryFailureBookie.

@Test
public void testRetryFailureBookie() throws Exception {
    ClientConfiguration conf = new ClientConfiguration();
    conf.setZkServers(zkUtil.getZooKeeperConnectString());
    conf.setDelayEnsembleChange(false).setDisableEnsembleChangeFeatureName(FEATURE_DISABLE_ENSEMBLE_CHANGE);
    SettableFeatureProvider featureProvider = new SettableFeatureProvider("test", 0);
    BookKeeper bkc = BookKeeper.forConfig(conf).featureProvider(featureProvider).build();
    SettableFeature disableEnsembleChangeFeature = featureProvider.getFeature(FEATURE_DISABLE_ENSEMBLE_CHANGE);
    disableEnsembleChangeFeature.set(true);
    LedgerHandle lh = bkc.createLedger(4, 4, 4, BookKeeper.DigestType.CRC32, new byte[] {});
    byte[] entry = "testRetryFailureBookie".getBytes();
    for (int i = 0; i < 10; i++) {
        lh.addEntry(entry);
    }
    // kill a bookie
    ServerConfiguration killedConf = killBookie(0);
    final AtomicInteger res = new AtomicInteger(0xdeadbeef);
    final CountDownLatch addLatch = new CountDownLatch(1);
    AsyncCallback.AddCallback cb = new AsyncCallback.AddCallback() {

        @Override
        public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
            logger.info("Add entry {} completed : rc {}.", entryId, rc);
            res.set(rc);
            addLatch.countDown();
        }
    };
    lh.asyncAddEntry(entry, cb, null);
    assertFalse("Add entry operation should not complete.", addLatch.await(1000, TimeUnit.MILLISECONDS));
    assertEquals(res.get(), 0xdeadbeef);
    // start the original bookie
    bsConfs.add(killedConf);
    bs.add(startBookie(killedConf));
    assertTrue("Add entry operation should complete at this point.", addLatch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(res.get(), BKException.Code.OK);
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Example 8 with SettableFeatureProvider

use of org.apache.bookkeeper.feature.SettableFeatureProvider in project distributedlog by twitter.

the class DLMTestUtil method injectLogSegmentWithGivenLogSegmentSeqNo.

public static void injectLogSegmentWithGivenLogSegmentSeqNo(DistributedLogManager manager, DistributedLogConfiguration conf, long logSegmentSeqNo, long startTxID, boolean writeEntries, long segmentSize, boolean completeLogSegment) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) manager;
    BKLogWriteHandler writeHandler = dlm.createWriteHandler(false);
    FutureUtils.result(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = dlm.getWriterBKC();
    LedgerHandle lh = bkc.get().createLedger(conf.getEnsembleSize(), conf.getWriteQuorumSize(), conf.getAckQuorumSize(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes());
    String inprogressZnodeName = writeHandler.inprogressZNodeName(lh.getId(), startTxID, logSegmentSeqNo);
    String znodePath = writeHandler.inprogressZNode(lh.getId(), startTxID, logSegmentSeqNo);
    LogSegmentMetadata l = new LogSegmentMetadata.LogSegmentMetadataBuilder(znodePath, conf.getDLLedgerMetadataLayoutVersion(), lh.getId(), startTxID).setLogSegmentSequenceNo(logSegmentSeqNo).build();
    l.write(dlm.writerZKC);
    writeHandler.maxTxId.store(startTxID);
    writeHandler.addLogSegmentToCache(inprogressZnodeName, l);
    BKLogSegmentWriter writer = new BKLogSegmentWriter(writeHandler.getFullyQualifiedName(), inprogressZnodeName, conf, conf.getDLLedgerMetadataLayoutVersion(), new BKLogSegmentEntryWriter(lh), writeHandler.lock, startTxID, logSegmentSeqNo, writeHandler.scheduler, writeHandler.statsLogger, writeHandler.statsLogger, writeHandler.alertStatsLogger, PermitLimiter.NULL_PERMIT_LIMITER, new SettableFeatureProvider("", 0), ConfUtils.getConstDynConf(conf));
    if (writeEntries) {
        long txid = startTxID;
        for (long j = 1; j <= segmentSize; j++) {
            writer.write(DLMTestUtil.getLogRecordInstance(txid++));
        }
        FutureUtils.result(writer.flushAndCommit());
    }
    if (completeLogSegment) {
        FutureUtils.result(writeHandler.completeAndCloseLogSegment(writer));
    }
    FutureUtils.result(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(com.twitter.distributedlog.impl.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Example 9 with SettableFeatureProvider

use of org.apache.bookkeeper.feature.SettableFeatureProvider in project distributedlog by twitter.

the class DLMTestUtil method injectLogSegmentWithLastDLSN.

public static void injectLogSegmentWithLastDLSN(DistributedLogManager manager, DistributedLogConfiguration conf, long logSegmentSeqNo, long startTxID, long segmentSize, boolean recordWrongLastDLSN) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) manager;
    BKLogWriteHandler writeHandler = dlm.createWriteHandler(false);
    FutureUtils.result(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = dlm.getReaderBKC();
    LedgerHandle lh = bkc.get().createLedger(conf.getEnsembleSize(), conf.getWriteQuorumSize(), conf.getAckQuorumSize(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes());
    String inprogressZnodeName = writeHandler.inprogressZNodeName(lh.getId(), startTxID, logSegmentSeqNo);
    String znodePath = writeHandler.inprogressZNode(lh.getId(), startTxID, logSegmentSeqNo);
    LogSegmentMetadata l = new LogSegmentMetadata.LogSegmentMetadataBuilder(znodePath, conf.getDLLedgerMetadataLayoutVersion(), lh.getId(), startTxID).setLogSegmentSequenceNo(logSegmentSeqNo).setInprogress(false).build();
    l.write(dlm.writerZKC);
    writeHandler.maxTxId.store(startTxID);
    writeHandler.addLogSegmentToCache(inprogressZnodeName, l);
    BKLogSegmentWriter writer = new BKLogSegmentWriter(writeHandler.getFullyQualifiedName(), inprogressZnodeName, conf, conf.getDLLedgerMetadataLayoutVersion(), new BKLogSegmentEntryWriter(lh), writeHandler.lock, startTxID, logSegmentSeqNo, writeHandler.scheduler, writeHandler.statsLogger, writeHandler.statsLogger, writeHandler.alertStatsLogger, PermitLimiter.NULL_PERMIT_LIMITER, new SettableFeatureProvider("", 0), ConfUtils.getConstDynConf(conf));
    long txid = startTxID;
    DLSN wrongDLSN = null;
    for (long j = 1; j <= segmentSize; j++) {
        DLSN dlsn = Await.result(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(txid++)));
        if (j == (segmentSize - 1)) {
            wrongDLSN = dlsn;
        }
    }
    assertNotNull(wrongDLSN);
    if (recordWrongLastDLSN) {
        FutureUtils.result(writer.asyncClose());
        writeHandler.completeAndCloseLogSegment(writeHandler.inprogressZNodeName(writer.getLogSegmentId(), writer.getStartTxId(), writer.getLogSegmentSequenceNumber()), writer.getLogSegmentSequenceNumber(), writer.getLogSegmentId(), writer.getStartTxId(), startTxID + segmentSize - 2, writer.getPositionWithinLogSegment() - 1, wrongDLSN.getEntryId(), wrongDLSN.getSlotId());
    } else {
        FutureUtils.result(writeHandler.completeAndCloseLogSegment(writer));
    }
    FutureUtils.result(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(com.twitter.distributedlog.impl.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Example 10 with SettableFeatureProvider

use of org.apache.bookkeeper.feature.SettableFeatureProvider in project bookkeeper by apache.

the class DLMTestUtil method injectLogSegmentWithLastDLSN.

public static void injectLogSegmentWithLastDLSN(DistributedLogManager manager, DistributedLogConfiguration conf, long logSegmentSeqNo, long startTxID, long segmentSize, boolean recordWrongLastDLSN) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) manager;
    BKLogWriteHandler writeHandler = dlm.createWriteHandler(false);
    Utils.ioResult(writeHandler.lockHandler());
    // Start a log segment with a given ledger seq number.
    BookKeeperClient bkc = getBookKeeperClient(dlm);
    LedgerHandle lh = bkc.get().createLedger(conf.getEnsembleSize(), conf.getWriteQuorumSize(), conf.getAckQuorumSize(), BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes());
    String inprogressZnodeName = writeHandler.inprogressZNodeName(lh.getId(), startTxID, logSegmentSeqNo);
    String znodePath = writeHandler.inprogressZNode(lh.getId(), startTxID, logSegmentSeqNo);
    LogSegmentMetadata l = new LogSegmentMetadata.LogSegmentMetadataBuilder(znodePath, conf.getDLLedgerMetadataLayoutVersion(), lh.getId(), startTxID).setLogSegmentSequenceNo(logSegmentSeqNo).setInprogress(false).build();
    l.write(getZooKeeperClient(dlm));
    writeHandler.maxTxId.update(Version.ANY, startTxID);
    writeHandler.addLogSegmentToCache(inprogressZnodeName, l);
    BKLogSegmentWriter writer = new BKLogSegmentWriter(writeHandler.getFullyQualifiedName(), inprogressZnodeName, conf, conf.getDLLedgerMetadataLayoutVersion(), new BKLogSegmentEntryWriter(lh), writeHandler.lock, startTxID, logSegmentSeqNo, writeHandler.scheduler, writeHandler.statsLogger, writeHandler.statsLogger, writeHandler.alertStatsLogger, PermitLimiter.NULL_PERMIT_LIMITER, new SettableFeatureProvider("", 0), ConfUtils.getConstDynConf(conf));
    long txid = startTxID;
    DLSN wrongDLSN = null;
    for (long j = 1; j <= segmentSize; j++) {
        DLSN dlsn = Utils.ioResult(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(txid++)));
        if (j == (segmentSize - 1)) {
            wrongDLSN = dlsn;
        }
    }
    assertNotNull(wrongDLSN);
    if (recordWrongLastDLSN) {
        Utils.ioResult(writer.asyncClose());
        writeHandler.completeAndCloseLogSegment(writeHandler.inprogressZNodeName(writer.getLogSegmentId(), writer.getStartTxId(), writer.getLogSegmentSequenceNumber()), writer.getLogSegmentSequenceNumber(), writer.getLogSegmentId(), writer.getStartTxId(), startTxID + segmentSize - 2, writer.getPositionWithinLogSegment() - 1, wrongDLSN.getEntryId(), wrongDLSN.getSlotId());
    } else {
        Utils.ioResult(writeHandler.completeAndCloseLogSegment(writer));
    }
    Utils.ioResult(writeHandler.unlockHandler());
}
Also used : BKLogSegmentEntryWriter(org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Aggregations

SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)16 URI (java.net.URI)6 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)6 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)5 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)5 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)4 HashSet (java.util.HashSet)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 Test (org.junit.Test)3 BKLogSegmentEntryWriter (com.twitter.distributedlog.impl.BKLogSegmentEntryWriter)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)2 BKLogSegmentEntryWriter (org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter)2 AsyncFailureInjector (org.apache.distributedlog.injector.AsyncFailureInjector)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1