use of org.apache.pulsar.metadata.api.MetadataStore in project pulsar by apache.
the class PulsarInitialNamespaceSetup method doMain.
public static int doMain(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 0;
}
if (arguments.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("initialize-namespace", arguments);
cmd.run(null);
return 0;
}
} catch (Exception e) {
jcommander.usage();
return 1;
}
if (arguments.configurationStore == null) {
System.err.println("Configuration store address argument is required (--configuration-store)");
jcommander.usage();
return 1;
}
try (MetadataStore configStore = PulsarClusterMetadataSetup.initMetadataStore(arguments.configurationStore, arguments.zkSessionTimeoutMillis)) {
PulsarResources pulsarResources = new PulsarResources(null, configStore);
for (String namespace : arguments.namespaces) {
NamespaceName namespaceName = null;
try {
namespaceName = NamespaceName.get(namespace);
} catch (Exception e) {
System.out.println("Invalid namespace name.");
return 1;
}
// Create specified tenant
PulsarClusterMetadataSetup.createTenantIfAbsent(pulsarResources, namespaceName.getTenant(), arguments.cluster);
// Create specified namespace
PulsarClusterMetadataSetup.createNamespaceIfAbsent(pulsarResources, namespaceName, arguments.cluster);
}
}
System.out.println("Initial namespace setup success");
return 0;
}
use of org.apache.pulsar.metadata.api.MetadataStore in project pulsar by apache.
the class IsolatedBookieEnsemblePlacementPolicy method initialize.
@Override
public RackawareEnsemblePlacementPolicyImpl initialize(ClientConfiguration conf, Optional<DNSToSwitchMapping> optionalDnsResolver, HashedWheelTimer timer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) {
Object storeProperty = conf.getProperty(BookieRackAffinityMapping.METADATA_STORE_INSTANCE);
if (storeProperty == null) {
throw new RuntimeException(BookieRackAffinityMapping.METADATA_STORE_INSTANCE + " configuration was not set in the BK client configuration");
}
if (!(storeProperty instanceof MetadataStore)) {
throw new RuntimeException(BookieRackAffinityMapping.METADATA_STORE_INSTANCE + " is not an instance of MetadataStore");
}
MetadataStore store = (MetadataStore) storeProperty;
Set<String> primaryIsolationGroups = new HashSet<>();
Set<String> secondaryIsolationGroups = new HashSet<>();
if (conf.getProperty(ISOLATION_BOOKIE_GROUPS) != null) {
String isolationGroupsString = castToString(conf.getProperty(ISOLATION_BOOKIE_GROUPS));
if (!isolationGroupsString.isEmpty()) {
for (String isolationGroup : isolationGroupsString.split(",")) {
primaryIsolationGroups.add(isolationGroup);
}
// Only add the bookieMappingCache if we have defined an isolation group
bookieMappingCache = store.getMetadataCache(BookiesRackConfiguration.class);
bookieMappingCache.get(BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH).join();
}
}
if (conf.getProperty(SECONDARY_ISOLATION_BOOKIE_GROUPS) != null) {
String secondaryIsolationGroupsString = castToString(conf.getProperty(SECONDARY_ISOLATION_BOOKIE_GROUPS));
if (!secondaryIsolationGroupsString.isEmpty()) {
for (String isolationGroup : secondaryIsolationGroupsString.split(",")) {
secondaryIsolationGroups.add(isolationGroup);
}
}
}
defaultIsolationGroups = ImmutablePair.of(primaryIsolationGroups, secondaryIsolationGroups);
return super.initialize(conf, optionalDnsResolver, timer, featureProvider, statsLogger, bookieAddressResolver);
}
use of org.apache.pulsar.metadata.api.MetadataStore in project pulsar by apache.
the class BookKeeperClientFactoryImplTest method testSetDefaultEnsemblePlacementPolicyRackAwareEnabled.
@Test
public void testSetDefaultEnsemblePlacementPolicyRackAwareEnabled() {
ClientConfiguration bkConf = new ClientConfiguration();
ServiceConfiguration conf = new ServiceConfiguration();
MetadataStore store = mock(MetadataStore.class);
assertNull(bkConf.getProperty(REPP_ENABLE_VALIDATION));
assertNull(bkConf.getProperty(REPP_REGIONS_TO_WRITE));
assertNull(bkConf.getProperty(REPP_MINIMUM_REGIONS_FOR_DURABILITY));
assertNull(bkConf.getProperty(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE));
assertNull(bkConf.getProperty(REPP_DNS_RESOLVER_CLASS));
assertNull(bkConf.getProperty(MIN_NUM_RACKS_PER_WRITE_QUORUM));
assertNull(bkConf.getProperty(ENFORCE_MIN_NUM_RACKS_PER_WRITE_QUORUM));
conf.setBookkeeperClientRegionawarePolicyEnabled(true);
BookKeeperClientFactoryImpl.setDefaultEnsemblePlacementPolicy(bkConf, conf, store);
assertTrue(bkConf.getBoolean(REPP_ENABLE_VALIDATION));
assertNull(bkConf.getString(REPP_REGIONS_TO_WRITE));
assertEquals(2, bkConf.getInt(REPP_MINIMUM_REGIONS_FOR_DURABILITY));
assertTrue(bkConf.getBoolean(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE));
assertEquals(bkConf.getProperty(REPP_DNS_RESOLVER_CLASS), BookieRackAffinityMapping.class.getName());
assertFalse(bkConf.getEnforceMinNumRacksPerWriteQuorum());
assertEquals(2, bkConf.getMinNumRacksPerWriteQuorum());
}
use of org.apache.pulsar.metadata.api.MetadataStore in project pulsar by apache.
the class BookKeeperClientFactoryImplTest method testSetDefaultEnsemblePlacementPolicyRackAwareEnabledChangedValues.
@Test
public void testSetDefaultEnsemblePlacementPolicyRackAwareEnabledChangedValues() {
ClientConfiguration bkConf = new ClientConfiguration();
ServiceConfiguration conf = new ServiceConfiguration();
MetadataStore store = mock(MetadataStore.class);
assertNull(bkConf.getProperty(REPP_ENABLE_VALIDATION));
assertNull(bkConf.getProperty(REPP_REGIONS_TO_WRITE));
assertNull(bkConf.getProperty(REPP_MINIMUM_REGIONS_FOR_DURABILITY));
assertNull(bkConf.getProperty(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE));
assertNull(bkConf.getProperty(REPP_DNS_RESOLVER_CLASS));
assertNull(bkConf.getProperty(MIN_NUM_RACKS_PER_WRITE_QUORUM));
assertNull(bkConf.getProperty(ENFORCE_MIN_NUM_RACKS_PER_WRITE_QUORUM));
conf.setBookkeeperClientRegionawarePolicyEnabled(true);
conf.getProperties().setProperty(REPP_ENABLE_VALIDATION, "false");
conf.getProperties().setProperty(REPP_REGIONS_TO_WRITE, "region1;region2");
conf.getProperties().setProperty(REPP_MINIMUM_REGIONS_FOR_DURABILITY, "4");
conf.getProperties().setProperty(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE, "false");
conf.getProperties().setProperty(REPP_DNS_RESOLVER_CLASS, CachedDNSToSwitchMapping.class.getName());
conf.setBookkeeperClientMinNumRacksPerWriteQuorum(20);
conf.setBookkeeperClientEnforceMinNumRacksPerWriteQuorum(true);
BookKeeperClientFactoryImpl.setDefaultEnsemblePlacementPolicy(bkConf, conf, store);
assertFalse(bkConf.getBoolean(REPP_ENABLE_VALIDATION));
assertEquals("region1;region2", bkConf.getString(REPP_REGIONS_TO_WRITE));
assertEquals(4, bkConf.getInt(REPP_MINIMUM_REGIONS_FOR_DURABILITY));
assertFalse(bkConf.getBoolean(REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE));
assertEquals(bkConf.getProperty(REPP_DNS_RESOLVER_CLASS), CachedDNSToSwitchMapping.class.getName());
assertTrue(bkConf.getEnforceMinNumRacksPerWriteQuorum());
assertEquals(20, bkConf.getMinNumRacksPerWriteQuorum());
}
use of org.apache.pulsar.metadata.api.MetadataStore in project pulsar by apache.
the class LocalMemoryMetadataStoreTest method testSharedInstance.
@Test
public void testSharedInstance() throws Exception {
String url = "memory:" + UUID.randomUUID();
@Cleanup MetadataStore store1 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
@Cleanup MetadataStore store2 = MetadataStoreFactory.create(url, MetadataStoreConfig.builder().build());
store1.put("/test", "value".getBytes(StandardCharsets.UTF_8), Optional.empty()).join();
assertTrue(store1.exists("/test").join());
assertTrue(store2.exists("/test").join());
store2.delete("/test", Optional.empty()).join();
assertFalse(store2.exists("/test").join());
// The exists will be updated based on the cache invalidation in store1
Awaitility.await().untilAsserted(() -> {
assertFalse(store1.exists("/test").join());
});
}
Aggregations