|
89 | 89 | import org.apache.pulsar.common.naming.NamespaceBundle;
|
90 | 90 | import org.apache.pulsar.common.naming.NamespaceBundleFactory;
|
91 | 91 | import org.apache.pulsar.common.naming.NamespaceBundleSplitAlgorithm;
|
| 92 | +import org.apache.pulsar.common.naming.NamespaceBundles; |
92 | 93 | import org.apache.pulsar.common.naming.NamespaceName;
|
93 | 94 | import org.apache.pulsar.common.naming.TopicDomain;
|
94 | 95 | import org.apache.pulsar.common.naming.TopicName;
|
@@ -852,8 +853,10 @@ protected void splitServiceUnitOnceAndRetry(NamespaceService namespaceService,
|
852 | 853 | long startTime,
|
853 | 854 | CompletableFuture<Void> completionFuture) {
|
854 | 855 | ownChildBundles(childBundles, parentData)
|
855 |
| - .thenCompose(__ -> updateSplitNamespaceBundlesAsync( |
| 856 | + .thenCompose(__ -> getSplitNamespaceBundles( |
856 | 857 | namespaceService, bundleFactory, algorithm, parentBundle, childBundles, boundaries))
|
| 858 | + .thenCompose(namespaceBundles -> updateSplitNamespaceBundlesAsync( |
| 859 | + namespaceService, bundleFactory, parentBundle, namespaceBundles)) |
857 | 860 | .thenAccept(__ -> // Update bundled_topic cache for load-report-generation
|
858 | 861 | pulsar.getBrokerService().refreshTopicToStatsMaps(parentBundle))
|
859 | 862 | .thenAccept(__ -> pubAsync(parentBundle.toString(), new ServiceUnitStateData(
|
@@ -913,69 +916,69 @@ private CompletableFuture<Void> ownChildBundles(List<NamespaceBundle> childBundl
|
913 | 916 | }
|
914 | 917 | }
|
915 | 918 |
|
916 |
| - private CompletableFuture<Void> updateSplitNamespaceBundlesAsync( |
917 |
| - NamespaceService namespaceService, |
918 |
| - NamespaceBundleFactory bundleFactory, |
919 |
| - NamespaceBundleSplitAlgorithm algorithm, |
920 |
| - NamespaceBundle parentBundle, |
921 |
| - List<NamespaceBundle> childBundles, |
922 |
| - List<Long> boundaries) { |
923 |
| - CompletableFuture<Void> updateSplitNamespaceBundlesFuture = new CompletableFuture<>(); |
924 |
| - var namespaceName = parentBundle.getNamespaceObject(); |
| 919 | + private CompletableFuture<NamespaceBundles> getSplitNamespaceBundles(NamespaceService namespaceService, |
| 920 | + NamespaceBundleFactory bundleFactory, |
| 921 | + NamespaceBundleSplitAlgorithm algorithm, |
| 922 | + NamespaceBundle parentBundle, |
| 923 | + List<NamespaceBundle> childBundles, |
| 924 | + List<Long> boundaries) { |
| 925 | + CompletableFuture future = new CompletableFuture(); |
925 | 926 | final var debug = debug();
|
926 | 927 | var targetNsBundle = bundleFactory.getBundles(parentBundle.getNamespaceObject());
|
927 |
| - boolean updated = false; |
| 928 | + boolean found = false; |
928 | 929 | try {
|
929 | 930 | targetNsBundle.validateBundle(parentBundle);
|
930 | 931 | } catch (IllegalArgumentException e) {
|
931 | 932 | if (debug) {
|
932 | 933 | log.info("Namespace bundles do not contain the parent bundle:{}",
|
933 | 934 | parentBundle);
|
934 | 935 | }
|
935 |
| - for (var childBundle : childBundles){ |
| 936 | + for (var childBundle : childBundles) { |
936 | 937 | try {
|
937 | 938 | targetNsBundle.validateBundle(childBundle);
|
938 | 939 | if (debug) {
|
939 | 940 | log.info("Namespace bundles contain the child bundle:{}",
|
940 | 941 | childBundle);
|
941 | 942 | }
|
942 | 943 | } catch (Exception ex) {
|
943 |
| - updateSplitNamespaceBundlesFuture.completeExceptionally( |
| 944 | + future.completeExceptionally( |
944 | 945 | new BrokerServiceException.ServiceUnitNotReadyException(
|
945 | 946 | "Namespace bundles do not contain the child bundle:" + childBundle, e));
|
946 |
| - return updateSplitNamespaceBundlesFuture; |
| 947 | + return future; |
947 | 948 | }
|
948 | 949 | }
|
949 |
| - updated = true; |
| 950 | + found = true; |
950 | 951 | } catch (Exception e) {
|
951 |
| - updateSplitNamespaceBundlesFuture.completeExceptionally( |
| 952 | + future.completeExceptionally( |
952 | 953 | new BrokerServiceException.ServiceUnitNotReadyException(
|
953 | 954 | "Failed to validate the parent bundle in the namespace bundles.", e));
|
954 |
| - return updateSplitNamespaceBundlesFuture; |
| 955 | + return future; |
955 | 956 | }
|
956 |
| - if (updated) { |
957 |
| - updateSplitNamespaceBundlesFuture.complete(null); |
| 957 | + if (found) { |
| 958 | + future.complete(targetNsBundle); |
| 959 | + return future; |
958 | 960 | } else {
|
959 |
| - namespaceService.getSplitBoundary(parentBundle, algorithm, boundaries) |
960 |
| - .thenApply(splitBundlesPair -> splitBundlesPair.getLeft()) |
961 |
| - .thenCompose(splitNamespaceBundles -> |
962 |
| - namespaceService.updateNamespaceBundles( |
963 |
| - namespaceName, splitNamespaceBundles) |
964 |
| - .thenCompose(__ -> namespaceService.updateNamespaceBundlesForPolicies( |
965 |
| - namespaceName, splitNamespaceBundles))) |
966 |
| - .thenAccept(__ -> { |
967 |
| - bundleFactory.invalidateBundleCache(parentBundle.getNamespaceObject()); |
968 |
| - if (debug) { |
969 |
| - log.info("Successfully updated split namespace bundles and namespace bundle cache."); |
970 |
| - } |
971 |
| - updateSplitNamespaceBundlesFuture.complete(null); |
972 |
| - }) |
973 |
| - .exceptionally(ex -> { |
974 |
| - updateSplitNamespaceBundlesFuture.completeExceptionally(ex); |
975 |
| - return null; |
976 |
| - }); |
| 961 | + return namespaceService.getSplitBoundary(parentBundle, algorithm, boundaries) |
| 962 | + .thenApply(splitBundlesPair -> splitBundlesPair.getLeft()); |
977 | 963 | }
|
978 |
| - return updateSplitNamespaceBundlesFuture; |
| 964 | + } |
| 965 | + |
| 966 | + private CompletableFuture<Void> updateSplitNamespaceBundlesAsync( |
| 967 | + NamespaceService namespaceService, |
| 968 | + NamespaceBundleFactory bundleFactory, |
| 969 | + NamespaceBundle parentBundle, |
| 970 | + NamespaceBundles splitNamespaceBundles) { |
| 971 | + var namespaceName = parentBundle.getNamespaceObject(); |
| 972 | + return namespaceService.updateNamespaceBundles( |
| 973 | + namespaceName, splitNamespaceBundles) |
| 974 | + .thenCompose(__ -> namespaceService.updateNamespaceBundlesForPolicies( |
| 975 | + namespaceName, splitNamespaceBundles)) |
| 976 | + .thenAccept(__ -> { |
| 977 | + bundleFactory.invalidateBundleCache(parentBundle.getNamespaceObject()); |
| 978 | + if (debug()) { |
| 979 | + log.info("Successfully updated split namespace bundles and namespace bundle cache."); |
| 980 | + } |
| 981 | + }); |
979 | 982 | }
|
980 | 983 |
|
981 | 984 | public void handleMetadataSessionEvent(SessionEvent e) {
|
|
0 commit comments