Copilot commented on code in PR #3081:
URL: https://github.com/apache/hugegraph/pull/3081#discussion_r3663686279
##########
hugegraph-store/hg-store-rocksdb/src/main/java/org/apache/hugegraph/rocksdb/access/SessionOperatorImpl.java:
##########
@@ -208,7 +208,14 @@ public void deleteRange(byte[] keyFrom, byte[] keyTo)
throws DBStoreException {
@Override
public byte[] get(String table, byte[] key) throws DBStoreException {
try (CFHandleLock cf = this.getLock(table)) {
- return rocksdb().get(cf.get(), key);
+ byte[] value = rocksdb().get(cf.get(), key);
+ if (value != null) {
+ return value;
+ }
+ if (RocksDBFactory.getInstance().onReadMiss(this.session, table,
key)) {
Review Comment:
onReadMiss() can perform cloud hydration (network + filesystem I/O via
CloudStorageEventListener.restoreMissingLiveFiles()), but it is currently
invoked while holding CFHandleLock from getLock(table). This can block other
threads needing the same CF handle lock for the duration of hydration. Release
the CFHandleLock before calling onReadMiss(), then reacquire it to retry the
get().
##########
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:
captureMetadataCheckpoint() logs the original exception but drops it when
throwing DBStoreException, which makes diagnosing checkpoint failures harder
upstream. DBStoreException supports a (message, cause, args...) constructor, so
the cause can be preserved.
##########
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:
CloudStorageProviderFactory.initialize() dereferences config without a null
check, so callers get a NullPointerException on bad input. Since this is a
public factory API, prefer validating and throwing IllegalArgumentException
with a clear message.
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/BusinessHandlerImpl.java:
##########
@@ -1008,17 +1008,27 @@ public void batchGet(String graph, String table,
Supplier<HgPair<Integer, byte[]
}
/**
- * Clear map data
+ * Clear map data.
+ *
+ * <p>Fires {@code notifyTruncateBegin} before the key-range delete so that
+ * registered listeners can prepare for truncate and suppress racing
callbacks,
+ * and {@code notifyTruncate} afterwards so that listeners can finalize any
+ * post-truncate cleanup — matching the same callback pair fired by
+ * {@link org.apache.hugegraph.rocksdb.access.RocksDBSession#truncate()}.
*/
@Override
public void truncate(String graphName, int partId) throws HgStoreException
{
// Each partition corresponds to a rocksdb instance, so the rocksdb
instance name is
// rocksdb + partId
try (RocksDBSession dbSession = getSession(graphName, partId)) {
+ String dbName = dbSession.getGraphName();
+ String dbPath = dbSession.getDbPath();
+ factory.notifyTruncateBegin(dbName, dbPath);
dbSession.sessionOp().deleteRange(keyCreator.getStartKey(partId,
graphName),
keyCreator.getEndKey(partId,
graphName));
// Release map ID
keyCreator.delGraphId(partId, graphName);
+ factory.notifyTruncate(dbName, dbPath);
}
Review Comment:
truncate() fires notifyTruncateBegin(), but if deleteRange() or delGraphId()
throws, notifyTruncate() is skipped and listeners may remain stuck in a
“truncating” suppression state indefinitely. Mirror RocksDBSession.truncate()
by guaranteeing a terminal notification (notifyTruncate on success,
notifyTruncateAbort on failure) via try/finally.
##########
hugegraph-store/pom.xml:
##########
@@ -302,5 +307,13 @@
</plugins>
</build>
</profile>
+
+ <!-- Build the S3 cloud-storage plugin: mvn install -P cloud-s3
-DskipTests -->
+ <profile>
+ <id>cloud-s3</id>
+ <modules>
+ <module>hg-store-cloud-s3</module>
+ </modules>
+ </profile>
Review Comment:
The cloud-s3 Maven profile is currently redundant because hg-store-cloud-s3
is already listed under the top-level <modules>. Activating -P cloud-s3 will
not change the build, and in some Maven versions duplicate module declarations
can lead to confusing warnings. Consider removing the profile (or removing the
module from the default build if it truly should be profile-gated).
--
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]