Skip to content

Normalize the close protocol: close() -> release() -> tryClose() - #355

Merged
dfa1 merged 5 commits into
mainfrom
simplify-close
Nov 18, 2026
Merged

dfa1 merged 5 commits into
mainfrom
simplify-close

Conversation

@dfa1

@dfa1 dfa1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • One path: NativeObject.close() -> release() (swap the pointer once, call tryClose, log on failure) -> the class's own tryClose. NativeObjectChild.release() is the only override, wrapping it in the monitor a parent's sweep waits on and unregistering from the parents afterwards.
  • Gone: doRelease, afterRelease, NativeObjectParent's final tryClose with its tryCloseResource, and NativeDBWithBaseDB's tryCloseBaseDb/tryClosePrimary hooks.
  • A parent's own tryClose starts with releaseChildren() (EnvOptions, ReadOptions, Transaction, NativeDB, TransactionDB, OptimisticTransactionDB). The base DB wrapper is closed best-effort inside TransactionDB/OptimisticTransactionDB's tryClose, before the primary pointer.
  • Children-first ordering is no longer enforced by the base class; the parents are package-private, so we keep it by convention, and the parent tests cover the existing ones.

Refs #354 (a final close() with tryClose as the only virtual is a follow-up).

Test plan

  • ./mvnw test -pl core -am, ./mvnw package -pl core -am -DskipTests
  • CI on all platforms

🤖 Generated with Claude Code

Also: Transaction.commit/rollback release their children even when RocksDB reports an error (it clears the transaction first), and fakePtr moves to a shared TestPointers test helper. Closes #299.

dfa1 and others added 5 commits November 16, 2026 09:05
doRelease, afterRelease, NativeObjectParent's final tryClose with tryCloseResource,
and NativeDBWithBaseDB's tryCloseBaseDb/tryClosePrimary hooks are gone. A parent's
own tryClose starts with releaseChildren(); NativeObjectChild.release() adds the
monitor and the unregistration around NativeObject.release(). Refs #354.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Drops the lazily created set (volatile field, VarHandle CAS, null checks): it saved
two small objects on four parent classes. Also fixes stale AtomicReference wording.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…reports an error

RocksDB clears the transaction before returning most commit/rollback errors, which
invalidates its iterators and frees its snapshot; checkError throwing skipped the sweep
and left them registered over a cleared batch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ackToSavePoint has none

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Closes #299

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dfa1
dfa1 merged commit 84c85e9 into main Nov 18, 2026
7 checks passed
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.

Tests: share fakePtr(long) helper between NativeObjectTest and NativeObjectWithChildrenTest

1 participant