vaijosh commented on code in PR #3081:
URL: https://github.com/apache/hugegraph/pull/3081#discussion_r3666446417


##########
hugegraph-store/hg-store-common/src/main/java/org/apache/hugegraph/store/cloud/CloudStorageProviderFactory.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.hugegraph.store.cloud;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.Getter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Factory for {@link CloudStorageProvider} instances.
+ *
+ * <p>Providers are discovered at class-loading time via {@link ServiceLoader}.
+ * Any JAR that includes
+ * {@code 
META-INF/services/org.apache.hugegraph.store.cloud.CloudStorageProvider}
+ * is automatically picked up when it is present on the classpath.
+ *
+ * <p>Usage:
+ * <pre>
+ *   CloudStorageConfig cfg = ...; // populated from application.yml
+ *   CloudStorageProvider provider = 
CloudStorageProviderFactory.initialize(cfg);
+ *   // later:
+ *   CloudStorageProvider active = 
CloudStorageProviderFactory.getActiveProvider();
+ * </pre>
+ */
+public final class CloudStorageProviderFactory {
+
+    private static final Logger log = 
LoggerFactory.getLogger(CloudStorageProviderFactory.class);
+
+    /** All discovered providers keyed by {@link 
CloudStorageProvider#providerName()}. */
+    private static final Map<String, CloudStorageProvider> REGISTRY = new 
ConcurrentHashMap<>();
+
+    /** The currently active (initialized) provider; null when disabled or not 
yet initialized.
+     * -- GETTER --
+     *  Returns the currently active provider, or
+     *  if cloud storage is
+     *  disabled or
+     *  has not yet been called.
+     */
+    @Getter
+    private static volatile CloudStorageProvider activeProvider;
+
+    static {
+        loadProviders();
+    }
+
+    private CloudStorageProviderFactory() {
+    }
+
+    // -----------------------------------------------------------------------
+    // Public API
+    // -----------------------------------------------------------------------
+
+    /**
+     * Initializes and activates the cloud storage provider described by 
{@code config}.
+     *
+     * <p>The method is idempotent: if called multiple times, the existing 
active
+     * provider is closed before a new one is initialized.
+     *
+     * @param config cloud storage configuration
+     * @return the initialized provider, or {@code null} when
+     *         {@link CloudStorageConfig#isEnabled()} is {@code false}
+     * @throws IllegalArgumentException if no provider matching {@code 
config.getProvider()}
+     *                                  was found on the classpath
+     */
+    public static synchronized CloudStorageProvider 
initialize(CloudStorageConfig config) {
+        if (!config.isEnabled()) {
+            // Disabling cloud storage must deactivate any currently active 
provider: otherwise a

Review Comment:
   Addressed in latest commit



##########
hugegraph-store/hg-store-rocksdb/src/main/java/org/apache/hugegraph/rocksdb/access/RocksDBSession.java:
##########
@@ -693,6 +764,70 @@ public void saveSnapshot(String snapshotPath) throws 
DBStoreException {
                  System.currentTimeMillis() - startTime);
     }
 
+    /**
+     * Captures a consistent copy of this DB's metadata (CURRENT / MANIFEST-* 
/ OPTIONS-* / WAL) plus
+     * hard-links to the live SST set into a temporary directory, using a 
RocksDB
+     * {@link Checkpoint}. See {@link 
RocksDBFactory#captureMetadataSnapshot(String)} for the metadata
+     * rationale.
+     *
+     * <p>The temporary directory is a sibling of the DB directory (same 
filesystem), so SST files
+     * are hard-linked rather than copied. The caller owns cleanup via
+     * {@link RocksDBFactory.MetadataSnapshot#cleanup()}.
+     *
+     * @return the captured snapshot; never {@code null}
+     * @throws DBStoreException if the checkpoint cannot be created
+     */
+    RocksDBFactory.MetadataSnapshot captureMetadataCheckpoint() throws 
DBStoreException {
+        String tempDir = this.dbPath + "_cloudmeta_" + System.nanoTime();
+        cfHandleLock.readLock().lock();
+        try (final Checkpoint checkpoint = Checkpoint.create(this.rocksDB)) {
+            final File tempFile = new File(tempDir);
+            // Clean any stale temp checkpoint dir from a previous 
failed/interrupted attempt.
+            // If it exists, RocksDB checkpoint creation can fail on 
pre-existing files.
+            FileUtils.deleteDirectory(tempFile);
+            checkpoint.createCheckpoint(tempDir);
+        } catch (final Exception e) {
+            try {
+                FileUtils.deleteDirectory(new File(tempDir));
+            } catch (IOException ignore) {
+                // best-effort cleanup of a partial checkpoint
+            }
+            log.error("Fail to create metadata checkpoint at {}", tempDir, e);
+            throw new DBStoreException(
+                    String.format("Fail to create metadata checkpoint at %s", 
tempDir));

Review Comment:
   Addressed in latest commit



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to