Search in sources :

Example 1 with BrokerPersistenceException

use of org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException in project pulsar by apache.

the class BrokerBookieIsolationTest method testBookieIsolationWithSecondaryGroup.

/**
 * It verifies that "ZkIsolatedBookieEnsemblePlacementPolicy" considers secondary affinity-group if primary group
 * doesn't have enough non-faulty bookies.
 *
 * @throws Exception
 */
@Test
public void testBookieIsolationWithSecondaryGroup() throws Exception {
    final String tenant1 = "tenant1";
    final String cluster = "use";
    final String ns1 = String.format("%s/%s/%s", tenant1, cluster, "ns1");
    final String ns2 = String.format("%s/%s/%s", tenant1, cluster, "ns2");
    final String ns3 = String.format("%s/%s/%s", tenant1, cluster, "ns3");
    final String ns4 = String.format("%s/%s/%s", tenant1, cluster, "ns4");
    final int totalPublish = 100;
    final String brokerBookkeeperClientIsolationGroups = "default-group";
    final String tenantNamespaceIsolationGroupsPrimary = "tenant1-isolation-primary";
    final String tenantNamespaceIsolationGroupsSecondary = "tenant1-isolation=secondary";
    BookieServer[] bookies = bkEnsemble.getBookies();
    ZooKeeper zkClient = bkEnsemble.getZkClient();
    Set<BookieId> defaultBookies = Sets.newHashSet(bookies[0].getBookieId(), bookies[1].getBookieId());
    Set<BookieId> isolatedBookies = Sets.newHashSet(bookies[2].getBookieId(), bookies[3].getBookieId());
    Set<BookieId> downedBookies = Sets.newHashSet(BookieId.parse("1.1.1.1:1111"), BookieId.parse("1.1.1.1:1112"));
    setDefaultIsolationGroup(brokerBookkeeperClientIsolationGroups, zkClient, defaultBookies);
    // primary group empty
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsPrimary, zkClient, downedBookies);
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsSecondary, zkClient, isolatedBookies);
    ServiceConfiguration config = new ServiceConfiguration();
    config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config.setClusterName(cluster);
    config.setWebServicePort(Optional.of(0));
    config.setMetadataStoreUrl("zk:127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerShutdownTimeoutMs(0L);
    config.setBrokerServicePort(Optional.of(0));
    config.setAdvertisedAddress("localhost");
    config.setBookkeeperClientIsolationGroups(brokerBookkeeperClientIsolationGroups);
    config.setManagedLedgerDefaultEnsembleSize(2);
    config.setManagedLedgerDefaultWriteQuorum(2);
    config.setManagedLedgerDefaultAckQuorum(2);
    config.setAllowAutoTopicCreationType("non-partitioned");
    int totalEntriesPerLedger = 20;
    int totalLedgers = totalPublish / totalEntriesPerLedger;
    config.setManagedLedgerMaxEntriesPerLedger(totalEntriesPerLedger);
    config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
    pulsarService = new PulsarService(config);
    pulsarService.start();
    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarService.getWebServiceAddress()).build();
    ClusterData clusterData = ClusterData.builder().serviceUrl(pulsarService.getWebServiceAddress()).build();
    admin.clusters().createCluster(cluster, clusterData);
    TenantInfoImpl tenantInfo = new TenantInfoImpl(null, Sets.newHashSet(cluster));
    admin.tenants().createTenant(tenant1, tenantInfo);
    admin.namespaces().createNamespace(ns1);
    admin.namespaces().createNamespace(ns2);
    admin.namespaces().createNamespace(ns3);
    admin.namespaces().createNamespace(ns4);
    admin.namespaces().setBookieAffinityGroup(ns2, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns3, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns4, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns2), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns3), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns4), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    try {
        admin.namespaces().getBookieAffinityGroup(ns1);
    } catch (PulsarAdminException.NotFoundException e) {
    // Ok
    }
    @Cleanup PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarService.getBrokerServiceUrl()).statsInterval(-1, TimeUnit.SECONDS).build();
    PersistentTopic topic1 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns1, "topic1", totalPublish);
    PersistentTopic topic2 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns2, "topic1", totalPublish);
    PersistentTopic topic3 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns3, "topic1", totalPublish);
    Bookie bookie1 = bookies[0].getBookie();
    Field ledgerManagerField = Bookie.class.getDeclaredField("ledgerManager");
    ledgerManagerField.setAccessible(true);
    LedgerManager ledgerManager = (LedgerManager) ledgerManagerField.get(bookie1);
    // namespace: ns1
    ManagedLedgerImpl ml = (ManagedLedgerImpl) topic1.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), defaultBookies);
    // namespace: ns2
    ml = (ManagedLedgerImpl) topic2.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    // namespace: ns3
    ml = (ManagedLedgerImpl) topic3.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    ManagedLedgerClientFactory mlFactory = (ManagedLedgerClientFactory) pulsarService.getManagedLedgerClientFactory();
    Map<EnsemblePlacementPolicyConfig, BookKeeper> bkPlacementPolicyToBkClientMap = mlFactory.getBkEnsemblePolicyToBookKeeperMap();
    // broker should create only 1 bk-client and factory per isolation-group
    assertEquals(bkPlacementPolicyToBkClientMap.size(), 1);
    // ns4 doesn't have secondary group so, publish should fail
    try {
        PersistentTopic topic4 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns4, "topic1", 1);
        fail("should have failed due to not enough non-faulty bookie");
    } catch (BrokerPersistenceException e) {
    // Ok..
    }
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) BookieServer(org.apache.bookkeeper.proto.BookieServer) Cleanup(lombok.Cleanup) ManagedLedgerClientFactory(org.apache.pulsar.broker.ManagedLedgerClientFactory) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) Field(java.lang.reflect.Field) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) Bookie(org.apache.bookkeeper.bookie.Bookie) PulsarClient(org.apache.pulsar.client.api.PulsarClient) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) BookKeeper(org.apache.bookkeeper.client.BookKeeper) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) ZooKeeper(org.apache.zookeeper.ZooKeeper) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) BrokerPersistenceException(org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 2 with BrokerPersistenceException

use of org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException in project pulsar by yahoo.

the class BrokerBookieIsolationTest method testBookieIsolationWithSecondaryGroup.

/**
 * It verifies that "ZkIsolatedBookieEnsemblePlacementPolicy" considers secondary affinity-group if primary group
 * doesn't have enough non-faulty bookies.
 *
 * @throws Exception
 */
@Test
public void testBookieIsolationWithSecondaryGroup() throws Exception {
    final String tenant1 = "tenant1";
    final String cluster = "use";
    final String ns1 = String.format("%s/%s/%s", tenant1, cluster, "ns1");
    final String ns2 = String.format("%s/%s/%s", tenant1, cluster, "ns2");
    final String ns3 = String.format("%s/%s/%s", tenant1, cluster, "ns3");
    final String ns4 = String.format("%s/%s/%s", tenant1, cluster, "ns4");
    final int totalPublish = 100;
    final String brokerBookkeeperClientIsolationGroups = "default-group";
    final String tenantNamespaceIsolationGroupsPrimary = "tenant1-isolation-primary";
    final String tenantNamespaceIsolationGroupsSecondary = "tenant1-isolation=secondary";
    BookieServer[] bookies = bkEnsemble.getBookies();
    ZooKeeper zkClient = bkEnsemble.getZkClient();
    Set<BookieId> defaultBookies = Sets.newHashSet(bookies[0].getBookieId(), bookies[1].getBookieId());
    Set<BookieId> isolatedBookies = Sets.newHashSet(bookies[2].getBookieId(), bookies[3].getBookieId());
    Set<BookieId> downedBookies = Sets.newHashSet(BookieId.parse("1.1.1.1:1111"), BookieId.parse("1.1.1.1:1112"));
    setDefaultIsolationGroup(brokerBookkeeperClientIsolationGroups, zkClient, defaultBookies);
    // primary group empty
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsPrimary, zkClient, downedBookies);
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsSecondary, zkClient, isolatedBookies);
    ServiceConfiguration config = new ServiceConfiguration();
    config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config.setClusterName(cluster);
    config.setWebServicePort(Optional.of(0));
    config.setMetadataStoreUrl("zk:127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerShutdownTimeoutMs(0L);
    config.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
    config.setBrokerServicePort(Optional.of(0));
    config.setAdvertisedAddress("localhost");
    config.setBookkeeperClientIsolationGroups(brokerBookkeeperClientIsolationGroups);
    config.setManagedLedgerDefaultEnsembleSize(2);
    config.setManagedLedgerDefaultWriteQuorum(2);
    config.setManagedLedgerDefaultAckQuorum(2);
    config.setAllowAutoTopicCreationType("non-partitioned");
    int totalEntriesPerLedger = 20;
    int totalLedgers = totalPublish / totalEntriesPerLedger;
    config.setManagedLedgerMaxEntriesPerLedger(totalEntriesPerLedger);
    config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
    pulsarService = new PulsarService(config);
    pulsarService.start();
    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarService.getWebServiceAddress()).build();
    ClusterData clusterData = ClusterData.builder().serviceUrl(pulsarService.getWebServiceAddress()).build();
    admin.clusters().createCluster(cluster, clusterData);
    TenantInfoImpl tenantInfo = new TenantInfoImpl(null, Sets.newHashSet(cluster));
    admin.tenants().createTenant(tenant1, tenantInfo);
    admin.namespaces().createNamespace(ns1);
    admin.namespaces().createNamespace(ns2);
    admin.namespaces().createNamespace(ns3);
    admin.namespaces().createNamespace(ns4);
    admin.namespaces().setBookieAffinityGroup(ns2, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns3, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns4, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns2), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns3), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns4), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    try {
        admin.namespaces().getBookieAffinityGroup(ns1);
        fail("ns1 should have no bookie affinity group set");
    } catch (PulsarAdminException.NotFoundException e) {
    // Ok
    }
    @Cleanup PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarService.getBrokerServiceUrl()).statsInterval(-1, TimeUnit.SECONDS).build();
    PersistentTopic topic1 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns1, "topic1", totalPublish);
    PersistentTopic topic2 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns2, "topic1", totalPublish);
    PersistentTopic topic3 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns3, "topic1", totalPublish);
    BookieImpl bookie1 = (BookieImpl) bookies[0].getBookie();
    LedgerManager ledgerManager = getLedgerManager(bookie1);
    // namespace: ns1
    ManagedLedgerImpl ml = (ManagedLedgerImpl) topic1.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), defaultBookies);
    // namespace: ns2
    ml = (ManagedLedgerImpl) topic2.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    // namespace: ns3
    ml = (ManagedLedgerImpl) topic3.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    ManagedLedgerClientFactory mlFactory = (ManagedLedgerClientFactory) pulsarService.getManagedLedgerClientFactory();
    Map<EnsemblePlacementPolicyConfig, BookKeeper> bkPlacementPolicyToBkClientMap = mlFactory.getBkEnsemblePolicyToBookKeeperMap();
    // broker should create only 1 bk-client and factory per isolation-group
    assertEquals(bkPlacementPolicyToBkClientMap.size(), 1);
    // ns4 doesn't have secondary group so, publish should fail
    try {
        PersistentTopic topic4 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns4, "topic1", 1);
        fail("should have failed due to not enough non-faulty bookie");
    } catch (BrokerPersistenceException e) {
    // Ok..
    }
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) BookieServer(org.apache.bookkeeper.proto.BookieServer) Cleanup(lombok.Cleanup) ManagedLedgerClientFactory(org.apache.pulsar.broker.ManagedLedgerClientFactory) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarClient(org.apache.pulsar.client.api.PulsarClient) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) BookKeeper(org.apache.bookkeeper.client.BookKeeper) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) ZooKeeper(org.apache.zookeeper.ZooKeeper) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) BrokerPersistenceException(org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 3 with BrokerPersistenceException

use of org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException in project incubator-pulsar by apache.

the class BrokerBookieIsolationTest method testBookieIsolationWithSecondaryGroup.

/**
 * It verifies that "ZkIsolatedBookieEnsemblePlacementPolicy" considers secondary affinity-group if primary group
 * doesn't have enough non-faulty bookies.
 *
 * @throws Exception
 */
@Test
public void testBookieIsolationWithSecondaryGroup() throws Exception {
    final String tenant1 = "tenant1";
    final String cluster = "use";
    final String ns1 = String.format("%s/%s/%s", tenant1, cluster, "ns1");
    final String ns2 = String.format("%s/%s/%s", tenant1, cluster, "ns2");
    final String ns3 = String.format("%s/%s/%s", tenant1, cluster, "ns3");
    final String ns4 = String.format("%s/%s/%s", tenant1, cluster, "ns4");
    final int totalPublish = 100;
    final String brokerBookkeeperClientIsolationGroups = "default-group";
    final String tenantNamespaceIsolationGroupsPrimary = "tenant1-isolation-primary";
    final String tenantNamespaceIsolationGroupsSecondary = "tenant1-isolation=secondary";
    BookieServer[] bookies = bkEnsemble.getBookies();
    ZooKeeper zkClient = bkEnsemble.getZkClient();
    Set<BookieId> defaultBookies = Sets.newHashSet(bookies[0].getBookieId(), bookies[1].getBookieId());
    Set<BookieId> isolatedBookies = Sets.newHashSet(bookies[2].getBookieId(), bookies[3].getBookieId());
    Set<BookieId> downedBookies = Sets.newHashSet(BookieId.parse("1.1.1.1:1111"), BookieId.parse("1.1.1.1:1112"));
    setDefaultIsolationGroup(brokerBookkeeperClientIsolationGroups, zkClient, defaultBookies);
    // primary group empty
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsPrimary, zkClient, downedBookies);
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsSecondary, zkClient, isolatedBookies);
    ServiceConfiguration config = new ServiceConfiguration();
    config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config.setClusterName(cluster);
    config.setWebServicePort(Optional.of(0));
    config.setMetadataStoreUrl("zk:127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerShutdownTimeoutMs(0L);
    config.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
    config.setBrokerServicePort(Optional.of(0));
    config.setAdvertisedAddress("localhost");
    config.setBookkeeperClientIsolationGroups(brokerBookkeeperClientIsolationGroups);
    config.setManagedLedgerDefaultEnsembleSize(2);
    config.setManagedLedgerDefaultWriteQuorum(2);
    config.setManagedLedgerDefaultAckQuorum(2);
    config.setAllowAutoTopicCreationType("non-partitioned");
    int totalEntriesPerLedger = 20;
    int totalLedgers = totalPublish / totalEntriesPerLedger;
    config.setManagedLedgerMaxEntriesPerLedger(totalEntriesPerLedger);
    config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
    pulsarService = new PulsarService(config);
    pulsarService.start();
    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarService.getWebServiceAddress()).build();
    ClusterData clusterData = ClusterData.builder().serviceUrl(pulsarService.getWebServiceAddress()).build();
    admin.clusters().createCluster(cluster, clusterData);
    TenantInfoImpl tenantInfo = new TenantInfoImpl(null, Sets.newHashSet(cluster));
    admin.tenants().createTenant(tenant1, tenantInfo);
    admin.namespaces().createNamespace(ns1);
    admin.namespaces().createNamespace(ns2);
    admin.namespaces().createNamespace(ns3);
    admin.namespaces().createNamespace(ns4);
    admin.namespaces().setBookieAffinityGroup(ns2, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns3, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    admin.namespaces().setBookieAffinityGroup(ns4, BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns2), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns3), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).bookkeeperAffinityGroupSecondary(tenantNamespaceIsolationGroupsSecondary).build());
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns4), BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary(tenantNamespaceIsolationGroupsPrimary).build());
    try {
        admin.namespaces().getBookieAffinityGroup(ns1);
        fail("ns1 should have no bookie affinity group set");
    } catch (PulsarAdminException.NotFoundException e) {
    // Ok
    }
    @Cleanup PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarService.getBrokerServiceUrl()).statsInterval(-1, TimeUnit.SECONDS).build();
    PersistentTopic topic1 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns1, "topic1", totalPublish);
    PersistentTopic topic2 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns2, "topic1", totalPublish);
    PersistentTopic topic3 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns3, "topic1", totalPublish);
    BookieImpl bookie1 = (BookieImpl) bookies[0].getBookie();
    LedgerManager ledgerManager = getLedgerManager(bookie1);
    // namespace: ns1
    ManagedLedgerImpl ml = (ManagedLedgerImpl) topic1.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), defaultBookies);
    // namespace: ns2
    ml = (ManagedLedgerImpl) topic2.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    // namespace: ns3
    ml = (ManagedLedgerImpl) topic3.getManagedLedger();
    assertEquals(ml.getLedgersInfoAsList().size(), totalLedgers);
    // validate ledgers' ensemble with affinity bookies
    assertAffinityBookies(ledgerManager, ml.getLedgersInfoAsList(), isolatedBookies);
    ManagedLedgerClientFactory mlFactory = (ManagedLedgerClientFactory) pulsarService.getManagedLedgerClientFactory();
    Map<EnsemblePlacementPolicyConfig, BookKeeper> bkPlacementPolicyToBkClientMap = mlFactory.getBkEnsemblePolicyToBookKeeperMap();
    // broker should create only 1 bk-client and factory per isolation-group
    assertEquals(bkPlacementPolicyToBkClientMap.size(), 1);
    // ns4 doesn't have secondary group so, publish should fail
    try {
        PersistentTopic topic4 = (PersistentTopic) createTopicAndPublish(pulsarClient, ns4, "topic1", 1);
        fail("should have failed due to not enough non-faulty bookie");
    } catch (BrokerPersistenceException e) {
    // Ok..
    }
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) BookieServer(org.apache.bookkeeper.proto.BookieServer) Cleanup(lombok.Cleanup) ManagedLedgerClientFactory(org.apache.pulsar.broker.ManagedLedgerClientFactory) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarClient(org.apache.pulsar.client.api.PulsarClient) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) BookKeeper(org.apache.bookkeeper.client.BookKeeper) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) ZooKeeper(org.apache.zookeeper.ZooKeeper) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) BrokerPersistenceException(org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Aggregations

Cleanup (lombok.Cleanup)3 BookKeeper (org.apache.bookkeeper.client.BookKeeper)3 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 BookieId (org.apache.bookkeeper.net.BookieId)3 BookieServer (org.apache.bookkeeper.proto.BookieServer)3 ManagedLedgerClientFactory (org.apache.pulsar.broker.ManagedLedgerClientFactory)3 PulsarService (org.apache.pulsar.broker.PulsarService)3 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3 ModularLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl)3 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)3 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 PulsarClient (org.apache.pulsar.client.api.PulsarClient)3 BrokerPersistenceException (org.apache.pulsar.client.api.PulsarClientException.BrokerPersistenceException)3 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)3 EnsemblePlacementPolicyConfig (org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig)3 TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Test (org.testng.annotations.Test)3