Search in sources :

Example 1 with SettableFeature

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

the class ConfigurationFeatureProvider method makeFeature.

static SettableFeature makeFeature(ConcurrentBaseConfiguration featuresConf, ConcurrentMap<String, SettableFeature> features, String featureName) {
    SettableFeature feature = features.get(featureName);
    if (null == feature) {
        int availability = featuresConf.getInt(featureName, 0);
        feature = new SettableFeature(featureName, availability);
        SettableFeature oldFeature = features.putIfAbsent(featureName, feature);
        if (null != oldFeature) {
            feature = oldFeature;
        } else {
            logger.info("Load feature {}={}", featureName, availability);
        }
    }
    return feature;
}
Also used : SettableFeature(org.apache.bookkeeper.feature.SettableFeature)

Example 2 with SettableFeature

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

the class TestWriteLimiter method testDarkmodeWithDisabledFeature.

@Test(timeout = 60000)
public void testDarkmodeWithDisabledFeature() throws Exception {
    SettableFeature feature = new SettableFeature("test", 10000);
    SimplePermitLimiter streamLimiter = createPermitLimiter(true, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(true, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 3 with SettableFeature

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

the class TestWriteLimiter method testSetDisableFeatureAfterAcquireAndBeforeRelease.

@Test(timeout = 60000)
public void testSetDisableFeatureAfterAcquireAndBeforeRelease() throws Exception {
    SettableFeature feature = new SettableFeature("test", 0);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 2, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
    feature.set(10000);
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 4 with SettableFeature

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

the class TestWriteLimiter method testDisabledFeature.

@Test(timeout = 60000)
public void testDisabledFeature() throws Exception {
    // Disable darkmode, but should still ignore limits because of the feature.
    SettableFeature feature = new SettableFeature("test", 10000);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 5 with SettableFeature

use of org.apache.bookkeeper.feature.SettableFeature 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)

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