use of org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer in project pulsar by apache.
the class LocalBookkeeperEnsemble method runStreamStorage.
public void runStreamStorage(CompositeConfiguration conf) throws Exception {
String zkServers = "127.0.0.1:" + zkPort;
String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";
URI metadataServiceUri = URI.create(metadataServiceUriStr);
// zookeeper servers
conf.setProperty("metadataServiceUri", metadataServiceUriStr);
// dlog settings
conf.setProperty("dlog.bkcEnsembleSize", 1);
conf.setProperty("dlog.bkcWriteQuorumSize", 1);
conf.setProperty("dlog.bkcAckQuorumSize", 1);
// stream storage port
conf.setProperty("storageserver.grpc.port", streamStoragePort);
// storage server settings
conf.setProperty("storage.range.store.dirs", bkDataDirName + "/ranges/data");
// initialize the stream storage metadata
ClusterInitializer initializer = new ZkClusterInitializer(zkServers);
initializer.initializeCluster(metadataServiceUri, 2);
// load the stream storage component
ServerConfiguration serverConf = new ServerConfiguration();
serverConf.loadConf(conf);
BookieConfiguration bkConf = new BookieConfiguration(serverConf);
this.streamStorage = new StreamStorageLifecycleComponent(bkConf, NullStatsLogger.INSTANCE);
this.streamStorage.start();
LOG.debug("Local BK stream storage started (port: {})", streamStoragePort);
// create a default namespace
try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(StorageClientSettings.newBuilder().serviceUri("bk://localhost:4181").backoffPolicy(Backoff.Jitter.of(Type.EXPONENTIAL, 1000, 10000, 30)).build()).buildAdmin()) {
try {
NamespaceProperties ns = FutureUtils.result(admin.getNamespace("default"));
LOG.info("'default' namespace for table service : {}", ns);
} catch (NamespaceNotFoundException nnfe) {
LOG.info("Creating default namespace");
try {
NamespaceProperties ns = FutureUtils.result(admin.createNamespace("default", NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
LOG.info("Successfully created 'default' namespace :\n{}", ns);
} catch (NamespaceExistsException nee) {
// namespace already exists
LOG.warn("Namespace 'default' already existed.");
}
}
}
}
use of org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer in project incubator-pulsar by apache.
the class LocalBookkeeperEnsemble method runStreamStorage.
public void runStreamStorage(CompositeConfiguration conf) throws Exception {
String zkServers = "127.0.0.1:" + zkPort;
String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";
URI metadataServiceUri = URI.create(metadataServiceUriStr);
// zookeeper servers
conf.setProperty("metadataServiceUri", metadataServiceUriStr);
// dlog settings
conf.setProperty("dlog.bkcEnsembleSize", 1);
conf.setProperty("dlog.bkcWriteQuorumSize", 1);
conf.setProperty("dlog.bkcAckQuorumSize", 1);
// stream storage port
conf.setProperty("storageserver.grpc.port", streamStoragePort);
// storage server settings
conf.setProperty("storage.range.store.dirs", bkDataDirName + "/ranges/data");
// initialize the stream storage metadata
ClusterInitializer initializer = new ZkClusterInitializer(zkServers);
initializer.initializeCluster(metadataServiceUri, 2);
// load the stream storage component
ServerConfiguration serverConf = new ServerConfiguration();
serverConf.loadConf(conf);
BookieConfiguration bkConf = new BookieConfiguration(serverConf);
this.streamStorage = new StreamStorageLifecycleComponent(bkConf, NullStatsLogger.INSTANCE);
this.streamStorage.start();
LOG.debug("Local BK stream storage started (port: {})", streamStoragePort);
// create a default namespace
try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(StorageClientSettings.newBuilder().serviceUri("bk://localhost:4181").backoffPolicy(Backoff.Jitter.of(Type.EXPONENTIAL, 1000, 10000, 30)).build()).buildAdmin()) {
try {
NamespaceProperties ns = FutureUtils.result(admin.getNamespace("default"));
LOG.info("'default' namespace for table service : {}", ns);
} catch (NamespaceNotFoundException nnfe) {
LOG.info("Creating default namespace");
try {
NamespaceProperties ns = FutureUtils.result(admin.createNamespace("default", NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
LOG.info("Successfully created 'default' namespace :\n{}", ns);
} catch (NamespaceExistsException nee) {
// namespace already exists
LOG.warn("Namespace 'default' already existed.");
}
}
}
}
use of org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer in project bookkeeper by apache.
the class BKCluster method start.
public void start() throws Exception {
// start the metadata store
if (enableContainerLog) {
this.metadataContainer.tailContainerLog();
}
this.metadataContainer.start();
log.info("Successfully started metadata store container.");
// init a new cluster
initNewCluster(metadataContainer.getExternalServiceUri());
log.info("Successfully initialized metadata service uri : {}", metadataContainer.getExternalServiceUri());
if (!Strings.isNullOrEmpty(extraServerComponents)) {
int numStorageContainers = numBookies > 0 ? 2 * numBookies : 8;
// initialize the stream storage.
new ZkClusterInitializer(ZKMetadataDriverBase.getZKServersFromServiceUri(URI.create(metadataContainer.getExternalServiceUri()))).initializeCluster(URI.create(metadataContainer.getInternalServiceUri()), numStorageContainers);
log.info("Successfully initialized stream storage metadata with {} storage containers", numStorageContainers);
}
// create bookies
createBookies("bookie", numBookies);
}
use of org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer in project bookkeeper by apache.
the class StreamCluster method initializeCluster.
private void initializeCluster() throws Exception {
checkArgument(ServiceURI.SERVICE_ZK.equals(metadataServiceUri.getServiceName()), "Only support zookeeper based metadata service now");
String[] serviceHosts = metadataServiceUri.getServiceHosts();
String metadataServers = StringUtils.join(serviceHosts, ',');
new ZkClusterInitializer(metadataServers).initializeCluster(metadataServiceUri.getUri(), spec.numServers() * 2);
// format the bookkeeper cluster
MetadataDrivers.runFunctionWithMetadataBookieDriver(newBookieConfiguration(metadataServiceUri), driver -> {
try (RegistrationManager rm = driver.createRegistrationManager()) {
boolean initialized = rm.initNewCluster();
if (initialized) {
log.info("Successfully initialized the segment storage");
} else {
log.info("The segment storage was already initialized");
}
} catch (Exception e) {
throw new StorageRuntimeException("Failed to initialize the segment storage", e);
}
return null;
});
}
use of org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer in project incubator-pulsar by apache.
the class PulsarClusterMetadataSetup method main.
public static void main(String[] args) throws Exception {
System.setProperty("bookkeeper.metadata.bookie.drivers", PulsarMetadataBookieDriver.class.getName());
System.setProperty("bookkeeper.metadata.client.drivers", PulsarMetadataClientDriver.class.getName());
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander();
try {
jcommander.addObject(arguments);
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
return;
}
if (arguments.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("initialize-cluster-metadata", arguments);
cmd.run(null);
return;
}
} catch (Exception e) {
jcommander.usage();
throw e;
}
if (arguments.metadataStoreUrl == null && arguments.zookeeper == null) {
System.err.println("Metadata store address argument is required (--metadata-store)");
jcommander.usage();
System.exit(1);
}
if (arguments.configurationMetadataStore == null && arguments.configurationStore == null && arguments.globalZookeeper == null) {
System.err.println("Configuration metadata store address argument is required (--configuration-metadata-store)");
jcommander.usage();
System.exit(1);
}
if (arguments.configurationMetadataStore != null && (arguments.configurationStore != null || arguments.globalZookeeper != null)) {
System.err.println("Configuration metadata store argument (--configuration-metadata-store) " + "supersedes the deprecated (--global-zookeeper and --configuration-store) argument");
jcommander.usage();
System.exit(1);
}
if (arguments.configurationMetadataStore == null) {
arguments.configurationMetadataStore = arguments.configurationStore == null ? arguments.globalZookeeper : arguments.configurationStore;
}
if (arguments.metadataStoreUrl == null) {
arguments.metadataStoreUrl = ZKMetadataStore.ZK_SCHEME_IDENTIFIER + arguments.zookeeper;
}
if (arguments.numTransactionCoordinators <= 0) {
System.err.println("Number of transaction coordinators must greater than 0");
System.exit(1);
}
log.info("Setting up cluster {} with metadata-store={} configuration-metadata-store={}", arguments.cluster, arguments.metadataStoreUrl, arguments.configurationMetadataStore);
MetadataStoreExtended localStore = initMetadataStore(arguments.metadataStoreUrl, arguments.zkSessionTimeoutMillis);
MetadataStoreExtended configStore = initMetadataStore(arguments.configurationMetadataStore, arguments.zkSessionTimeoutMillis);
final String metadataStoreUrlNoIdentifer = MetadataStoreFactoryImpl.removeIdentifierFromMetadataURL(arguments.metadataStoreUrl);
// Format BookKeeper ledger storage metadata
if (arguments.existingBkMetadataServiceUri == null && arguments.bookieMetadataServiceUri == null) {
ServerConfiguration bkConf = new ServerConfiguration();
bkConf.setDelimiterParsingDisabled(true);
bkConf.setMetadataServiceUri("metadata-store:" + arguments.metadataStoreUrl);
bkConf.setZkTimeout(arguments.zkSessionTimeoutMillis);
// only format if /ledgers doesn't exist
if (!localStore.exists(BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH).get() && !BookKeeperAdmin.format(bkConf, false, /* interactive */
false)) {
throw new IOException("Failed to initialize BookKeeper metadata");
}
}
if (localStore instanceof ZKMetadataStore && configStore instanceof ZKMetadataStore) {
String uriStr;
if (arguments.existingBkMetadataServiceUri != null) {
uriStr = arguments.existingBkMetadataServiceUri;
} else if (arguments.bookieMetadataServiceUri != null) {
uriStr = arguments.bookieMetadataServiceUri;
} else {
uriStr = "zk+null://" + metadataStoreUrlNoIdentifer + BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH;
}
// initial distributed log metadata
initialDlogNamespaceMetadata(arguments.configurationMetadataStore, uriStr);
ServiceURI bkMetadataServiceUri = ServiceURI.create(uriStr);
// Format BookKeeper stream storage metadata
if (arguments.numStreamStorageContainers > 0) {
ClusterInitializer initializer = new ZkClusterInitializer(metadataStoreUrlNoIdentifer);
initializer.initializeCluster(bkMetadataServiceUri.getUri(), arguments.numStreamStorageContainers);
}
}
if (!localStore.exists(BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH).get()) {
createMetadataNode(localStore, BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, "{}".getBytes());
}
PulsarResources resources = new PulsarResources(localStore, configStore);
ClusterData clusterData = ClusterData.builder().serviceUrl(arguments.clusterWebServiceUrl).serviceUrlTls(arguments.clusterWebServiceUrlTls).brokerServiceUrl(arguments.clusterBrokerServiceUrl).brokerServiceUrlTls(arguments.clusterBrokerServiceUrlTls).build();
if (!resources.getClusterResources().clusterExists(arguments.cluster)) {
resources.getClusterResources().createCluster(arguments.cluster, clusterData);
}
// Create marker for "global" cluster
ClusterData globalClusterData = ClusterData.builder().build();
if (!resources.getClusterResources().clusterExists("global")) {
resources.getClusterResources().createCluster("global", globalClusterData);
}
// Create public tenant, whitelisted to use the this same cluster, along with other clusters
createTenantIfAbsent(resources, TopicName.PUBLIC_TENANT, arguments.cluster);
// Create system tenant
createTenantIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE.getTenant(), arguments.cluster);
// Create default namespace
createNamespaceIfAbsent(resources, NamespaceName.get(TopicName.PUBLIC_TENANT, TopicName.DEFAULT_NAMESPACE), arguments.cluster);
// Create system namespace
createNamespaceIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE, arguments.cluster);
// Create transaction coordinator assign partitioned topic
createPartitionedTopic(configStore, SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN, arguments.numTransactionCoordinators);
localStore.close();
configStore.close();
log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
Aggregations