heesung-sn commented on code in PR #23301:
URL: https://github.com/apache/pulsar/pull/23301#discussion_r1766169190


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateTableViewSyncer.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pulsar.broker.loadbalance.extensions.channel;
+
+import static 
org.apache.pulsar.broker.ServiceConfiguration.ServiceUnitTableViewSyncerType.SystemTopicToMetadataStoreSyncer;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl.COMPACTION_THRESHOLD;
+import static 
org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl.configureSystemTopics;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import lombok.Cleanup;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.common.util.FutureUtil;
+import org.apache.pulsar.common.util.ObjectMapperFactory;
+
+/**
+ * Defines ServiceUnitTableViewSyncer.
+ * It syncs service unit(bundle) states between metadata store and system 
topic table views.
+ * One could enable this syncer before migration from one to the other and 
disable it after the migration finishes.
+ */
+@Slf4j
+public class ServiceUnitStateTableViewSyncer implements Closeable {
+    private static final int MAX_CONCURRENT_SYNC_COUNT = 100;
+    private static final int SYNC_WAIT_TIME_IN_SECS = 300;
+    private PulsarService pulsar;
+    private volatile ServiceUnitStateTableView systemTopicTableView;
+    private volatile ServiceUnitStateTableView metadataStoreTableView;
+    private volatile boolean isActive = false;
+
+
+    public void start(PulsarService pulsar)
+            throws IOException, TimeoutException, InterruptedException, 
ExecutionException {
+        if 
(!pulsar.getConfiguration().isLoadBalancerServiceUnitTableViewSyncerEnabled()) {
+            return;
+        }
+
+        if (isActive) {
+            return;
+        }
+        this.pulsar = pulsar;
+
+        try {
+
+            syncExistingItems();
+            // disable compaction
+            if (!configureSystemTopics(pulsar, 0)) {
+                throw new IllegalStateException("Failed to disable 
compaction");
+            }
+            syncTailItems();
+
+            isActive = true;
+
+        } catch (Throwable e) {
+            log.error("Failed to start ServiceUnitStateTableViewSyncer", e);
+            throw e;
+        }
+    }
+
+    private CompletableFuture<Void> syncToSystemTopic(String key, 
ServiceUnitStateData data) {
+        return systemTopicTableView.put(key, data);
+    }
+
+    private CompletableFuture<Void> syncToMetadataStore(String key, 
ServiceUnitStateData data) {
+        return metadataStoreTableView.put(key, data);
+    }
+
+    private CompletableFuture<Void> dummy(String key, ServiceUnitStateData 
data) {

Review Comment:
   This returns future in case it needs to be chained in async. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to