You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "georgereuben (via GitHub)" <gi...@apache.org> on 2025/08/09 14:12:47 UTC
[PR] [#7977] fix: resolve race condition in snapshot creation by adjusting lock usage [gravitino]
georgereuben opened a new pull request, #7997:
URL: https://github.com/apache/gravitino/pull/7997
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### 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?
(Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, describe the bug.)
Fix: #7977
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
With UTs added earlier
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7977] fix: resolve race condition in snapshot creation by adjusting lock usage [gravitino]
Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on code in PR #7997:
URL: https://github.com/apache/gravitino/pull/7997#discussion_r2265678906
##########
core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java:
##########
@@ -176,17 +176,10 @@ public void close() throws IOException {
}
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()
Review Comment:
I had added this method earlier. Just noticed that try catch blocks were not being used in other sections of the file so I'd removed it for consistency since I didn't think this one was important. Should I add it back?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7977] fix: resolve race condition in snapshot creation by adjusting lock usage [gravitino]
Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #7997:
URL: https://github.com/apache/gravitino/pull/7997#discussion_r2265684885
##########
core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java:
##########
@@ -176,17 +176,10 @@ public void close() throws IOException {
}
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()
Review Comment:
No problem, I think that's good.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7977] fix: resolve race condition in snapshot creation by adjusting lock usage [gravitino]
Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #7997:
URL: https://github.com/apache/gravitino/pull/7997#discussion_r2265548636
##########
core/src/test/java/org/apache/gravitino/storage/memory/TestMemoryEntityStore.java:
##########
@@ -176,17 +176,10 @@ public void close() throws IOException {
}
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()
Review Comment:
Any reason teh try/catch was removed?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7977] fix: resolve race condition in snapshot creation by adjusting lock usage [gravitino]
Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean merged PR #7997:
URL: https://github.com/apache/gravitino/pull/7997
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org