Search in sources :

Example 1 with MetadataStore

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;
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs)

Example 2 with MetadataStore

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);
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) BookiesRackConfiguration(org.apache.pulsar.common.policies.data.BookiesRackConfiguration) HashSet(java.util.HashSet)

Example 3 with MetadataStore

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());
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) BookieRackAffinityMapping(org.apache.pulsar.bookie.rackawareness.BookieRackAffinityMapping) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 4 with MetadataStore

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());
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) CachedDNSToSwitchMapping(org.apache.bookkeeper.net.CachedDNSToSwitchMapping) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 5 with MetadataStore

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());
    });
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Aggregations

MetadataStore (org.apache.pulsar.metadata.api.MetadataStore)137 Test (org.testng.annotations.Test)120 Cleanup (lombok.Cleanup)105 CompletionException (java.util.concurrent.CompletionException)42 ArrayList (java.util.ArrayList)36 Stat (org.apache.pulsar.metadata.api.Stat)36 Optional (java.util.Optional)33 CompletableFuture (java.util.concurrent.CompletableFuture)27 MetadataStoreConfig (org.apache.pulsar.metadata.api.MetadataStoreConfig)27 NotFoundException (org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException)27 IOException (java.io.IOException)24 List (java.util.List)24 Supplier (java.util.function.Supplier)24 Slf4j (lombok.extern.slf4j.Slf4j)24 MetadataStoreFactory (org.apache.pulsar.metadata.api.MetadataStoreFactory)24 Map (java.util.Map)21 TreeMap (java.util.TreeMap)21 Policies (org.apache.pulsar.common.policies.data.Policies)18 MetadataCache (org.apache.pulsar.metadata.api.MetadataCache)18 AlreadyExistsException (org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException)18