use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.
the class ZkBookieRackAffinityMapping method getAndSetZkCache.
private ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> getAndSetZkCache(Configuration conf) {
ZooKeeperCache zkCache = null;
if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
} else {
int zkTimeout;
String zkServers;
if (conf instanceof ClientConfiguration) {
zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
zkServers = ((ClientConfiguration) conf).getZkServers();
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(zkTimeout) {
};
try {
ZooKeeper zkClient = ZkUtils.createConnectedZookeeperClient(zkServers, w);
zkCache = new ZooKeeperCache(zkClient) {
};
conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
} catch (Exception e) {
LOG.error("Error creating zookeeper client", e);
}
} else {
LOG.error("No zk configurations available");
}
}
ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> zkDataCache = getZkBookieRackMappingCache(zkCache);
if (zkDataCache != null) {
zkDataCache.registerListener(this);
}
return zkDataCache;
}
use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.
the class ZkIsolatedBookieEnsemblePlacementPolicy method getAndSetZkCache.
private ZooKeeperCache getAndSetZkCache(Configuration conf) {
ZooKeeperCache zkCache = null;
if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
} else {
int zkTimeout;
String zkServers;
if (conf instanceof ClientConfiguration) {
zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
zkServers = ((ClientConfiguration) conf).getZkServers();
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(zkTimeout) {
};
try {
ZooKeeper zkClient = ZkUtils.createConnectedZookeeperClient(zkServers, w);
zkCache = new ZooKeeperCache(zkClient) {
};
conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
} catch (Exception e) {
LOG.error("Error creating zookeeper client", e);
}
} else {
LOG.error("No zk configurations available");
}
}
return zkCache;
}
use of org.apache.bookkeeper.conf.ClientConfiguration in project distributedlog by twitter.
the class BookKeeperClient method commonInitialization.
@SuppressWarnings("deprecation")
private synchronized void commonInitialization(DistributedLogConfiguration conf, String ledgersPath, ClientSocketChannelFactory channelFactory, StatsLogger statsLogger, HashedWheelTimer requestTimer, boolean registerExpirationHandler) throws IOException, InterruptedException, KeeperException {
ClientConfiguration bkConfig = new ClientConfiguration();
bkConfig.setAddEntryTimeout(conf.getBKClientWriteTimeout());
bkConfig.setReadTimeout(conf.getBKClientReadTimeout());
bkConfig.setZkLedgersRootPath(ledgersPath);
bkConfig.setZkTimeout(conf.getBKClientZKSessionTimeoutMilliSeconds());
bkConfig.setNumWorkerThreads(conf.getBKClientNumberWorkerThreads());
bkConfig.setEnsemblePlacementPolicy(RegionAwareEnsemblePlacementPolicy.class);
bkConfig.setZkRequestRateLimit(conf.getBKClientZKRequestRateLimit());
bkConfig.setProperty(RegionAwareEnsemblePlacementPolicy.REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME, DistributedLogConstants.DISALLOW_PLACEMENT_IN_REGION_FEATURE_NAME);
// reload configuration from dl configuration with settings prefixed with 'bkc.'
ConfUtils.loadConfiguration(bkConfig, conf, "bkc.");
Class<? extends DNSToSwitchMapping> dnsResolverCls;
try {
dnsResolverCls = conf.getEnsemblePlacementDnsResolverClass();
} catch (ConfigurationException e) {
LOG.error("Failed to load bk dns resolver : ", e);
throw new IOException("Failed to load bk dns resolver : ", e);
}
final DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(dnsResolverCls, conf.getBkDNSResolverOverrides());
this.bkc = BookKeeper.newBuilder().config(bkConfig).zk(zkc.get()).channelFactory(channelFactory).statsLogger(statsLogger).dnsResolver(dnsResolver).requestTimer(requestTimer).featureProvider(featureProvider.orNull()).build();
if (registerExpirationHandler) {
sessionExpireWatcher = this.zkc.registerExpirationHandler(this);
}
}
use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.
the class PulsarClusterMetadataSetup method main.
public static void main(String[] args) throws Exception {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander();
try {
jcommander.addObject(arguments);
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
return;
}
} catch (Exception e) {
jcommander.usage();
return;
}
log.info("Setting up cluster {} with zk={} global-zk={}", arguments.cluster, arguments.zookeeper, arguments.globalZookeeper);
// Format BookKeeper metadata
ClientConfiguration bkConf = new ClientConfiguration();
bkConf.setLedgerManagerFactoryClass(HierarchicalLedgerManagerFactory.class);
bkConf.setZkServers(arguments.zookeeper);
if (!BookKeeperAdmin.format(bkConf, false, /* interactive */
false)) {
throw new IOException("Failed to initialize BookKeeper metadata");
}
ZooKeeperClientFactory zkfactory = new ZookeeperClientFactoryImpl();
ZooKeeper localZk = zkfactory.create(arguments.zookeeper, SessionType.ReadWrite, 30000).get();
ZooKeeper globalZk = zkfactory.create(arguments.globalZookeeper, SessionType.ReadWrite, 30000).get();
localZk.create("/managed-ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
localZk.create("/namespace", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
try {
ZkUtils.createFullPathOptimistic(globalZk, "/admin/policies", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (NodeExistsException e) {
// Ignore
}
try {
ZkUtils.createFullPathOptimistic(globalZk, "/admin/clusters", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (NodeExistsException e) {
// Ignore
}
ClusterData clusterData = new ClusterData(arguments.clusterWebServiceUrl, arguments.clusterWebServiceUrlTls, arguments.clusterBrokerServiceUrl, arguments.clusterBrokerServiceUrlTls);
byte[] clusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(clusterData);
globalZk.create("/admin/clusters/" + arguments.cluster, clusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// Create marker for "global" cluster
ClusterData globalClusterData = new ClusterData(null, null);
byte[] globalClusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(globalClusterData);
try {
globalZk.create("/admin/clusters/global", globalClusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (NodeExistsException e) {
// Ignore
}
log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.
the class ZkBookieRackAffinityMappingTest method testBookieInfoChange.
@Test
public void testBookieInfoChange() throws Exception {
Map<String, Map<BookieSocketAddress, BookieInfo>> bookieMapping = new HashMap<>();
Map<BookieSocketAddress, BookieInfo> mainBookieGroup = new HashMap<>();
BookieInfo bookieInfo0 = new BookieInfo();
bookieInfo0.setRack("rack0");
mainBookieGroup.put(BOOKIE1, bookieInfo0);
BookieInfo bookieInfo1 = new BookieInfo();
bookieInfo1.setRack("rack1");
mainBookieGroup.put(BOOKIE2, bookieInfo1);
bookieMapping.put("group1", mainBookieGroup);
ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
ZkBookieRackAffinityMapping mapping = new ZkBookieRackAffinityMapping();
ClientConfiguration bkClientConf = new ClientConfiguration();
bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
});
mapping.setConf(bkClientConf);
List<String> racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
assertEquals(racks.get(0), "/rack0");
assertEquals(racks.get(1), "/rack1");
assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);
// add info for BOOKIE3 and check if the mapping picks up the change
Map<BookieSocketAddress, BookieInfo> secondaryBookieGroup = new HashMap<>();
BookieInfo bookieInfo2 = new BookieInfo();
bookieInfo2.setRack("rack0");
secondaryBookieGroup.put(BOOKIE3, bookieInfo2);
bookieMapping.put("group2", secondaryBookieGroup);
localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), -1);
// wait for the zk to notify and update the mappings
Thread.sleep(100);
racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
assertEquals(racks.get(0), "/rack0");
assertEquals(racks.get(1), "/rack1");
assertEquals(racks.get(2), "/rack0");
localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
Thread.sleep(100);
racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
assertEquals(racks.get(0), NetworkTopology.DEFAULT_RACK);
assertEquals(racks.get(1), NetworkTopology.DEFAULT_RACK);
assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);
}
Aggregations