imbajin commented on code in PR #3153:
URL: https://github.com/apache/hugegraph/pull/3153#discussion_r3851711405
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/BusinessHandlerImpl.java:
##########
@@ -1577,7 +1577,7 @@ private TxBuilderImpl(String graph, int partId,
RocksDBSession dbSession) {
public TxBuilder put(int code, String table, byte[] key, byte[] value)
throws
HgStoreException {
try {
- byte[] targetKey = keyCreator.getKey(this.partId, graph, code,
key);
+ byte[] targetKey = keyCreator.getKeyOrCreate(this.partId,
graph, code, key);
Review Comment:
‼️ Critical — The encoded ID is not fenced against `truncate()`/ID reuse
until `build().commit()` returns. `truncate()` deletes the graph range and
calls `delGraphId()`, after which another graph may receive the released ID
while this batch still holds keys encoded with it; a delayed commit can then
write under the new graph's prefix. Please coordinate ID release/reuse with
in-flight `TxBuilder` transactions (or bind allocation, commit, and release
atomically) and add a deterministic truncate/reuse concurrency test.
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/BusinessHandlerImpl.java:
##########
@@ -1577,7 +1577,7 @@ private TxBuilderImpl(String graph, int partId,
RocksDBSession dbSession) {
public TxBuilder put(int code, String table, byte[] key, byte[] value)
throws
HgStoreException {
try {
- byte[] targetKey = keyCreator.getKey(this.partId, graph, code,
key);
+ byte[] targetKey = keyCreator.getKeyOrCreate(this.partId,
graph, code, key);
Review Comment:
‼️ Critical — `getKeyOrCreate()` adds an exception path after
`TxBuilderImpl` has already called `op.prepare()`. ID exhaustion or a failed
`checkCount` scan is propagated as `HgStoreException`, but this method catches
only `DBStoreException`; `DataManagerImpl.write()` and
`DefaultDataMover.doWriteData()` also leave the builder without rollback.
Because `prepare()` holds `cfHandleReadLock`, a failed first batch can retain
the lock and session reference and block later table/partition operations.
Please make every failed `put`/`merge` roll back and close the session, or
perform allocation before preparing the transaction, and cover the failure path
in a test.
##########
hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/core/BatchGraphIsolationTest.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.core;
+
+import static org.apache.hugegraph.store.constant.HugeServerTables.TABLES_MAP;
+import static
org.apache.hugegraph.store.constant.HugeServerTables.VERTEX_TABLE;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.store.UnitTestBase;
+import org.apache.hugegraph.store.business.BusinessHandler;
+import org.apache.hugegraph.store.business.BusinessHandlerImpl;
+import org.apache.hugegraph.store.grpc.common.Key;
+import org.apache.hugegraph.store.grpc.common.OpType;
+import org.apache.hugegraph.store.grpc.session.BatchEntry;
+import org.apache.hugegraph.store.meta.PartitionManager;
+import org.apache.hugegraph.store.options.HgStoreEngineOptions;
+import org.apache.hugegraph.store.options.RaftRocksdbOptions;
+import org.apache.hugegraph.store.pd.FakePdServiceProvider;
+import org.apache.hugegraph.store.pd.PdProvider;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.alipay.sofa.jraft.util.StorageOptionsFactory;
+import com.google.protobuf.ByteString;
+
+public class BatchGraphIsolationTest {
+
+ private static final int PARTITION_ID = 0;
+ private static final int EMPTY_PARTITION_ID = 1;
+ private static final int KEY_CODE = 0;
+ private static final byte[] SHARED_KEY =
+ "shared-key".getBytes(StandardCharsets.UTF_8);
+
+ private static Path databasePath;
+ private static BusinessHandler handler;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ databasePath =
Files.createTempDirectory("hugegraph-batch-graph-isolation-");
+
+ Map<String, Object> rocksdbConfig = new HashMap<>();
+ rocksdbConfig.put("rocksdb.write_buffer_size", "1048576");
+ StorageOptionsFactory.releaseAllOptions();
+ RaftRocksdbOptions.initRocksdbGlobalConfig(rocksdbConfig);
+ BusinessHandlerImpl.initRocksdb(rocksdbConfig, null);
+
+ HgStoreEngineOptions options = new HgStoreEngineOptions();
+ options.setDataPath(databasePath.toString());
+ options.setRaftPath(databasePath.toString());
+
+ HgStoreEngineOptions.FakePdOptions fakePdOptions =
+ new HgStoreEngineOptions.FakePdOptions();
+ fakePdOptions.setPartitionCount(1);
Review Comment:
⚠️ Important — The empty-table/deadlock assertion is not running on a valid
configured partition. `partitionCount` is 1 and `hasPartition()` only accepts
partition 0, but `EMPTY_PARTITION_ID` is 1; the test therefore creates an extra
`00001` RocksDB and calls `getGraphIdOrCreate()` directly without the
`TxBuilderImpl.op.prepare()` lock used by the batch path. Please make partition
1 valid and exercise a first PUT/MERGE batch while `g+v` is absent, with a
timeout assertion, so this test covers the production deadlock regression.
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/BusinessHandlerImpl.java:
##########
@@ -1642,7 +1642,7 @@ public TxBuilder merge(int code, String table, byte[]
key, byte[] value) throws
HgStoreException {
try {
- byte[] targetKey = keyCreator.getKey(this.partId, graph, code,
key);
+ byte[] targetKey = keyCreator.getKeyOrCreate(this.partId,
graph, code, key);
Review Comment:
⚠️ Important — This new allocation happens before the enclosing batch
commits: `getGraphIdOrCreate()` persists and flushes the graph mapping/ID slot,
while `BusinessHandler.doBatch()` only rolls back the data `WriteBatch`. If a
later entry in the same PUT/MERGE batch fails, the graph ID remains consumed
even though no data was committed, and repeated failed batches can eventually
exhaust the ID space. Please make ID allocation transactional with the batch or
release newly allocated IDs on rollback, and add a failing-batch regression
test.
--
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]