Skip to content

[#7744] improvement(core): allow nested SqlSession call#8242

Merged
mchades merged 3 commits intoapache:mainfrom
mchades:issue-7744
Aug 26, 2025
Merged

[#7744] improvement(core): allow nested SqlSession call#8242
mchades merged 3 commits intoapache:mainfrom
mchades:issue-7744

Conversation

@mchades
Copy link
Contributor

@mchades mchades commented Aug 22, 2025

What changes were proposed in this pull request?

  • add sessionCount for lifecycle management

Why are the changes needed?

Fix: #7744

Does this PR introduce any user-facing change?

no

How was this patch tested?

tests added

@mchades mchades requested review from jerryshao and yuqi1129 August 22, 2025 01:52
@mchades
Copy link
Contributor Author

mchades commented Aug 25, 2025

@yuqi1129 could you please help to review this PR? thanks!

sessionCount.remove();
}
} else if (count < 0) {
// This should not happen if the session management is correct.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not happen, unless an unknown bug is introduced.

@yuqi1129
Copy link
Contributor

Can the PR also fix the one #8210 that tries to?

@mchades
Copy link
Contributor Author

mchades commented Aug 26, 2025

Can the PR also fix the one #8210 that tries to?

yes, the new commit I pushed can fixed that

@mchades mchades requested a review from yuqi1129 August 26, 2025 01:44
sessions.set(sqlSession);
return sqlSession;
}
sessionCount.set(sessionCount.get() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not atomic, you'd better use AtomicInteger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. While the ThreadLocal already ensures thread safety here, I agree that using AtomicInteger makes the intent of a counter more explicit and the code cleaner. I've made the change.

sessions.remove();
}
}
handleSessionClose(true, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change all the code style to handleSessionClose(true /** commit */, false /** rollback */); for better review.

@mchades mchades requested a review from jerryshao August 26, 2025 08:25
@jerryshao
Copy link
Contributor

@yuqi1129 can you please take another review?

@yuqi1129
Copy link
Contributor

@yuqi1129 can you please take another review?

I don't have any more valuable comments.

@mchades mchades merged commit 1ff0802 into apache:main Aug 26, 2025
37 of 45 checks passed
@mchades mchades deleted the issue-7744 branch August 26, 2025 13:58
diqiu50 pushed a commit to diqiu50/gravitino that referenced this pull request Sep 15, 2025
…#8242)

### What changes were proposed in this pull request?

- add sessionCount for lifecycle management

### Why are the changes needed?

Fix: apache#7744

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

tests added
bharos pushed a commit to bharos/gravitino that referenced this pull request Oct 3, 2025
…#8242)

### What changes were proposed in this pull request?

- add sessionCount for lifecycle management

### Why are the changes needed?

Fix: apache#7744

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

tests added
bharos pushed a commit to bharos/gravitino that referenced this pull request Oct 7, 2025
…#8242)

### What changes were proposed in this pull request?

- add sessionCount for lifecycle management

### Why are the changes needed?

Fix: apache#7744

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

tests added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] nested call SessionUtils.getWithoutCommit will cause session closed

3 participants