Search in sources :

Example 16 with SettableFeature

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

the class TestConfigurationFeatureProvider method testConfigurationFeatureProvider.

@Test(timeout = 60000)
public void testConfigurationFeatureProvider() throws Exception {
    String rootScope = "dl";
    ConcurrentBaseConfiguration featureConf = new ConcurrentBaseConfiguration();
    ConcurrentMap<String, SettableFeature> features = new ConcurrentHashMap<String, SettableFeature>();
    ConfigurationFeatureProvider featureProvider = new ConfigurationFeatureProvider(rootScope, featureConf, features);
    String featureName1 = "feature1";
    String fullFeatureName1 = rootScope + "." + featureName1;
    int availability1 = 1234;
    featureConf.setProperty(fullFeatureName1, availability1);
    Feature feature1 = featureProvider.getFeature(featureName1);
    assertEquals(availability1, feature1.availability());
    assertTrue(features.containsKey(fullFeatureName1));
    assertTrue(feature1 == features.get(fullFeatureName1));
    String subScope = "subscope";
    String featureName2 = "feature2";
    String fullFeatureName2 = rootScope + "." + subScope + "." + featureName2;
    int availability2 = 4321;
    featureConf.setProperty(fullFeatureName2, availability2);
    Feature feature2 = featureProvider.scope(subScope).getFeature(featureName2);
    assertEquals(availability2, feature2.availability());
    assertTrue(features.containsKey(fullFeatureName2));
    assertTrue(feature2 == features.get(fullFeatureName2));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Feature(org.apache.bookkeeper.feature.Feature) ConcurrentBaseConfiguration(org.apache.distributedlog.common.config.ConcurrentBaseConfiguration) Test(org.junit.Test)

Example 17 with SettableFeature

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

the class TestRollLogSegments method testDisableRollingLogSegments.

@Test(timeout = 60000)
public void testDisableRollingLogSegments() throws Exception {
    String name = "distrlog-disable-rolling-log-segments";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setOutputBufferSize(0);
    confLocal.setLogSegmentRollingIntervalMinutes(0);
    confLocal.setMaxLogSegmentBytes(40);
    int numEntries = 100;
    BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    SettableFeature disableLogSegmentRolling = (SettableFeature) dlm.getFeatureProvider().getFeature(CoreFeatureKeys.DISABLE_LOGSEGMENT_ROLLING.name().toLowerCase());
    disableLogSegmentRolling.set(true);
    final CountDownLatch latch = new CountDownLatch(numEntries);
    // send requests in parallel
    for (int i = 1; i <= numEntries; i++) {
        final int entryId = i;
        writer.write(DLMTestUtil.getLogRecordInstance(entryId)).whenComplete(new FutureEventListener<DLSN>() {

            @Override
            public void onSuccess(DLSN value) {
                logger.info("Completed entry {} : {}.", entryId, value);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable cause) {
            // nope
            }
        });
    }
    latch.await();
    // make sure all ensure blocks were executed
    writer.closeAndComplete();
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    dlm.close();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test) FlakyTest(org.apache.distributedlog.common.annotations.DistributedLogAnnotations.FlakyTest)

Example 18 with SettableFeature

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

the class TestRegionAwareEnsemblePlacementPolicy method testEnsembleWithThreeRegionsReplaceInternal.

public void testEnsembleWithThreeRegionsReplaceInternal(int minDurability, boolean disableDurability, boolean disableOneRegion) throws Exception {
    repp.uninitalize();
    repp = new RegionAwareEnsemblePlacementPolicy();
    conf.setProperty(REPP_REGIONS_TO_WRITE, "region1;region2;region3");
    conf.setProperty(REPP_MINIMUM_REGIONS_FOR_DURABILITY, minDurability);
    FeatureProvider featureProvider = new SettableFeatureProvider("", 0);
    if (minDurability <= 1) {
        conf.setProperty(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE, false);
    } else {
        conf.setProperty(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE, true);
    }
    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.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);
    // 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");
    // 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);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    SettableFeature disableDurabilityFeature = (SettableFeature) featureProvider.getFeature(BookKeeperConstants.FEATURE_REPP_DISABLE_DURABILITY_ENFORCEMENT);
    if (disableDurability) {
        disableDurabilityFeature.set(true);
    }
    int ackQuorum = 4;
    if (minDurability > 2) {
        ackQuorum = 5;
    }
    ArrayList<BookieSocketAddress> ensemble;
    try {
        ensemble = repp.newEnsemble(6, 6, ackQuorum, null, new HashSet<BookieSocketAddress>());
        assert (ensemble.size() == 6);
        assertEquals(3, getNumRegionsInEnsemble(ensemble));
    } catch (BKNotEnoughBookiesException bnebe) {
        LOG.error("BKNotEnoughBookiesException", bnebe);
        fail("Should not get not enough bookies exception even there is only one rack.");
        throw bnebe;
    }
    if (disableOneRegion) {
        ((SettableFeature) featureProvider.scope("region2").getFeature("disallowBookies")).set(true);
        Set<BookieSocketAddress> region2Bookies = new HashSet<BookieSocketAddress>();
        region2Bookies.add(addr4);
        region2Bookies.add(addr5);
        region2Bookies.add(addr6);
        Set<BookieSocketAddress> region1And3Bookies = new HashSet<BookieSocketAddress>(addrs);
        region1And3Bookies.removeAll(region2Bookies);
        Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
        for (BookieSocketAddress addr : region2Bookies) {
            if (ensemble.contains(addr)) {
                BookieSocketAddress replacedBookie = repp.replaceBookie(6, 6, ackQuorum, null, new HashSet<>(ensemble), addr, excludedAddrs);
                ensemble.remove(addr);
                ensemble.add(replacedBookie);
            }
        }
        assertEquals(2, getNumRegionsInEnsemble(ensemble));
        assertTrue(ensemble.containsAll(region1And3Bookies));
    } else {
        BookieSocketAddress bookieToReplace;
        BookieSocketAddress replacedBookieExpected;
        if (ensemble.contains(addr4)) {
            bookieToReplace = addr4;
            if (ensemble.contains(addr5)) {
                replacedBookieExpected = addr6;
            } else {
                replacedBookieExpected = addr5;
            }
        } else {
            replacedBookieExpected = addr4;
            bookieToReplace = addr5;
        }
        Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
        try {
            BookieSocketAddress replacedBookie = repp.replaceBookie(6, 6, ackQuorum, null, new HashSet<>(ensemble), bookieToReplace, excludedAddrs);
            assert (replacedBookie.equals(replacedBookieExpected));
            assertEquals(3, getNumRegionsInEnsemble(ensemble));
        } catch (BKNotEnoughBookiesException bnebe) {
            fail("Should not get not enough bookies exception even there is only one rack.");
        }
        excludedAddrs.add(replacedBookieExpected);
        try {
            BookieSocketAddress replacedBookie = repp.replaceBookie(6, 6, ackQuorum, null, new HashSet<>(ensemble), bookieToReplace, excludedAddrs);
            if (minDurability > 1 && !disableDurabilityFeature.isAvailable()) {
                fail("Should throw BKNotEnoughBookiesException when there is not enough bookies");
            }
        } catch (BKNotEnoughBookiesException bnebe) {
            if (minDurability <= 1 || disableDurabilityFeature.isAvailable()) {
                fail("Should not throw BKNotEnoughBookiesException when there is not enough bookies");
            }
        }
    }
}
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)

Example 19 with SettableFeature

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

the class TestDisableEnsembleChange method testRetrySlowBookie.

@Test
public void testRetrySlowBookie() throws Exception {
    final int readTimeout = 2;
    ClientConfiguration conf = new ClientConfiguration();
    conf.setReadEntryTimeout(readTimeout).setAddEntryTimeout(readTimeout).setDelayEnsembleChange(false).setDisableEnsembleChangeFeatureName(FEATURE_DISABLE_ENSEMBLE_CHANGE).setZkServers(zkUtil.getZooKeeperConnectString());
    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);
    }
    List<BookieSocketAddress> curEns = lh.getLedgerMetadata().currentEnsemble;
    final CountDownLatch wakeupLatch = new CountDownLatch(1);
    final CountDownLatch suspendLatch = new CountDownLatch(1);
    sleepBookie(curEns.get(2), wakeupLatch, suspendLatch);
    suspendLatch.await();
    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);
    // wait until read timeout
    assertFalse("Add entry operation should not complete even timeout.", addLatch.await(readTimeout, TimeUnit.SECONDS));
    assertEquals(res.get(), 0xdeadbeef);
    // wait one more read timeout, to ensure we resend multiple retries
    // to ensure it works correctly
    assertFalse("Add entry operation should not complete even timeout.", addLatch.await(readTimeout, TimeUnit.SECONDS));
    assertEquals(res.get(), 0xdeadbeef);
    // wakeup the sleep bookie
    wakeupLatch.countDown();
    assertTrue("Add entry operation should complete at this point.", addLatch.await(10000, TimeUnit.MILLISECONDS));
    assertEquals(res.get(), BKException.Code.OK);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Example 20 with SettableFeature

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

the class TestServiceRequestLimiter method testDynamicLimiterWithDisabledFeature.

@Test(timeout = 60000)
public void testDynamicLimiterWithDisabledFeature() throws Exception {
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    final MockSoftRequestLimiter rateLimiter = new MockSoftRequestLimiter(0);
    final SettableFeature disabledFeature = new SettableFeature("", 0);
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, disabledFeature) {

        @Override
        public RequestLimiter<MockRequest> build() {
            return rateLimiter;
        }
    };
    limiter.initialize();
    assertEquals(0, rateLimiter.getLimitHitCount());
    // Not disabled, rate limiter was invoked
    limiter.apply(new MockRequest(Integer.MAX_VALUE));
    assertEquals(1, rateLimiter.getLimitHitCount());
    // Disabled, rate limiter not invoked
    disabledFeature.set(1);
    limiter.apply(new MockRequest(Integer.MAX_VALUE));
    assertEquals(1, rateLimiter.getLimitHitCount());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Aggregations

SettableFeature (org.apache.bookkeeper.feature.SettableFeature)27 Test (org.junit.Test)22 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)6 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)5 SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)3 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)3 HashSet (java.util.HashSet)3 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)3 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)2 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Feature (org.apache.bookkeeper.feature.Feature)2 OverCapacityException (org.apache.distributedlog.exceptions.OverCapacityException)2