This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 4d9679699d [#7977] fix: resolve race condition in snapshot creation by
adjusting lock usage (#7997)
4d9679699d is described below
commit 4d9679699d23bc2ba18c1d626fa7ee2774144243
Author: Reuben George <[email protected]>
AuthorDate: Mon Aug 11 10:14:37 2025 +0530
[#7977] fix: resolve race condition in snapshot creation by adjusting lock
usage (#7997)
### What changes were proposed in this pull request?
Previously, the snapshot for rollback was created outside the lock,
which could lead to inconsistent state and race conditions in concurrent
scenarios.
This change ensures the snapshot is always created while holding the
lock, preventing data corruption and ensuring reliable transaction
rollback.
### Why are the changes needed?
Fix: #7977
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
With UTs added earlier
---
.../gravitino/storage/memory/TestMemoryEntityStore.java | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git
a/core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java
b/core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java
index 4bf70297e8..bdb37895d2 100644
---
a/core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java
+++
b/core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java
@@ -154,8 +154,8 @@ public class TestMemoryEntityStore {
@Override
public <R, E extends Exception> R executeInTransaction(Executable<R, E>
executable)
throws E, IOException {
- Map<NameIdentifier, Entity> snapshot = createSnapshot();
lock.lock();
+ Map<NameIdentifier, Entity> snapshot = createSnapshot();
try {
return executable.execute();
} catch (Exception e) {
@@ -176,17 +176,10 @@ public class TestMemoryEntityStore {
}
public Map<NameIdentifier, Entity> createSnapshot() {
- lock.lock();
- try {
- return entityMap.entrySet().stream()
- .collect(
- Collectors.toMap(
- Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1,
Maps::newHashMap));
- } catch (Exception e) {
- throw new RuntimeException("Failed to create snapshot of entity
store", e);
- } finally {
- lock.unlock();
- }
+ return entityMap.entrySet().stream()
+ .collect(
+ Collectors.toMap(
+ Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1,
Maps::newHashMap));
}
}