Repository navigation
cephsqlite: support concurrent readers - #69199
Conversation
a81176d to
c154540
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
4c73405 to
126f7ba
Compare
|
This PR has been added to main integration testing by pdonnell started 2026-06-09-12:34. |
d37d833 to
7d0218b
Compare
|
This PR has been added to main integration testing by pdonnell started 2026-07-12-17:08. |
f5a6e08 to
7b95725
Compare
|
Making some more adjustments but I think this is getting closer. |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@batrick, please see my comments
| d(10) << "escalating to Exclusive" << dendl; | ||
| /* allow Exclusive lock if Reserved <= lock state <= Pending */ | ||
| rados::cls::lock::lock(&op, primary, ClsLockType::EXCLUSIVE, cookie.to_string(), "", lockdesc, duration, flags); | ||
| op.cmpxattr(XATTR_STATE, LIBRADOS_CMPXATTR_OP_LTE, state2bl(LockLevel::Reserved)); |
There was a problem hiding this comment.
Going from Shared to Exclusive now always fails. The state on disk is Shared, but this check requires at least Reserved, so we get EBUSY every time
There was a problem hiding this comment.
You're looking at an out-of-date diff somehow.
| op.getxattr(XATTR_ALLOCATED, &bl_alloc, &prval_alloc); | ||
| op.getxattr(XATTR_EXCL, &bl_excl, &prval_excl); | ||
| op.getxattr(XATTR_LAYOUT_OBJECT_SIZE, &bl_layout_os, &prval_layout_os); | ||
| op.getxattr(XATTR_LAYOUT_STRIPE_COUNT, &bl_layout_sc, &prval_layout_sc); | ||
| op.getxattr(XATTR_LAYOUT_STRIPE_UNIT, &bl_layout_su, &prval_layout_su); | ||
| op.getxattr(XATTR_SIZE, &bl_size, &prval_size); | ||
| op.getxattr(XATTR_ALLOCATED, &bl_alloc, &prval_alloc); | ||
| op.getxattr(XATTR_STATE, &bl_state, &prval_state); | ||
| op.getxattr(XATTR_VERSION, &bl_version, &prval_version); | ||
| op.getxattr(XATTR_WRITE_EPOCH, &bl_epoch, &prval_epoch); |
There was a problem hiding this comment.
I don't think a failed getxattr is contained to its prval. In PrimaryLogPG::do_osd_ops() a getxattr on a missing xattr sets result = -ENODATA, and unless the op has FAILOK the loop breaks and the whole read returns -ENODATA, so operate() fails before any of the prval checks run. create() sets OP_FAILOK on the same reads for this reason.
It matters for upgrades: databases created before this PR don't have striper.state or striper.write_epoch, and since open() is just get_metadata(), I think opening any existing mgr database would fail with SQLITE_IOERR.
| d(10) << "escalating to Pending" << dendl; | ||
| /* allow Pending lock if lock state == Reserved */ | ||
| rados::cls::lock::lock(&op, primary, ClsLockType::SHARED, cookie.to_string(), "", lockdesc, duration, flags); | ||
| op.cmpxattr(XATTR_STATE, LIBRADOS_CMPXATTR_OP_LTE, state2bl(LockLevel::Reserved)); |
There was a problem hiding this comment.
This changed from OP_EQ to OP_LTE, but with " OP " that now means
ondisk >= Reserved, while the comment above still says "== Reserved".
That breaks the new Pending fallback for Shared -> Exclusive, which SQLite uses for hot-journal rollback (your HotJournalRollbackSharedToExclusive test).
When the Exclusive attempt gets EBUSY we switch to Pending, but the on-disk state is still Shared, so this cmpxattr fails with ECANCELED. That goes through recover_lock(), which finds striper.excl empty and returns EBUSY, and we never reach Pending. New readers are never held off, and each retry costs extra round trips.
Should this be OP_GTE (Reserved >= ondisk)?
The striper.excl check already makes sure nobody else holds Reserved. The test only checks the Reserved -> Exclusive path, so a two-client Shared -> Exclusive case would catch it.
There was a problem hiding this comment.
I'm cleaning this up more but it's not valid to stop in Reserved/Pending from Shared. So this doesn't matter in practice.
| db.execute('PRAGMA PAGE_SIZE = 65536') | ||
| db.execute('PRAGMA CACHE_SIZE = 64') | ||
| db.execute('PRAGMA TEMP_STORE = memory') | ||
| db.execute('PRAGMA busy_timeout = 60000') # 60s, longer than lock_keeper_timeout |
There was a problem hiding this comment.
Two small things. This runs after the earlier PRAGMAs and after the ceph_status() query in open_db(), so those still get Python's default 5s. Passing timeout= to sqlite3.connect() in open_db() would cover the whole connection. Also, the 60s is tied to the current default of cephsqlite_lock_renewal_timeout.
Could it be derived from that option instead, so raising the lease doesn't bring the failure back?
There was a problem hiding this comment.
Fixed it to come from the option.
7d8563c to
18f8754
Compare
|
Latest run passes: https://tracker.ceph.com/issues/82165 Will add a full orch/rados/upgrade too. |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@batrick, just 1 change is needed, but everything other than that looks good.
| self.log.debug(f"using uri {uri}") | ||
| db = sqlite3.connect(uri, check_same_thread=False, uri=True, isolation_level=None) # type: ignore[call-arg] | ||
| busy_timeout = 60.0 | ||
| lock_renewal_timeout = self.get_ceph_option('cephsqlite_lock_renewal_timeout') |
There was a problem hiding this comment.
cephsqlite_lock_renewal_timeout is in milliseconds, and sqlite3.connect timeout is in seconds. maybe / 1000 ?
This patch addresses two issues in the teardown phase: 1. `wait_for_aios(true)` is explicitly invoked to prevent in-flight AIO completions from being destroyed when `aios` goes out of scope, preventing memory corruption/segmentation faults. 2. The `shutdown` flag is now protected by the `lock_keeper_mutex` when toggled, preventing a race condition where the thread misses the notification and blocks indefinitely on thread join. Assisted-by: Gemini Signed-off-by: Patrick Donnelly <[email protected]>
Improves debug observability by logging the retrieved file size during `stat` operations. Assisted-by: Gemini Signed-off-by: Patrick Donnelly <[email protected]>
Appends the connection cookie to the `dout_prefix` output. This helps operators and developers easily differentiate between different database handles in the logs. Assisted-by: Gemini Signed-off-by: Patrick Donnelly <[email protected]>
Signed-off-by: Patrick Donnelly <[email protected]>
Instead of using an exclusive lock for all database access, allow shared reader locks to improve read-heavy workload throughput. This patch maps SQLite VFS locking states to Ceph RADOS advisory locks using a single primary lock object (`striper.lock`) paired with extended attributes (`striper.state` and `striper.excl`) to safely facilitate atomic lock escalation without deadlocks: - SQLITE_LOCK_SHARED (1): Acquires a SHARED lock on the primary object and verifies `striper.state` > None. - SQLITE_LOCK_RESERVED (2): Acquires a SHARED lock and sets `striper.state` to 2. Populates `striper.excl` with the client's address as a gatekeeper so only one client can intend to write at a time, bypassing the classic SQLite Upgrade Deadlock. - SQLITE_LOCK_PENDING (3): Upgrades `striper.state` to 3, blocking new readers. - SQLITE_LOCK_EXCLUSIVE (4): Upgrades the RADOS lock to EXCLUSIVE and sets `striper.state` to 4. Returns -EBUSY cleanly if other SHARED readers still exist, ensuring no transactional state is corrupted. Additionally implements `xCheckReservedLock` by checking the reservation state via `striper.state` to quickly report if any client currently holds intent to write, satisfying SQLite's concurrency requirements. Assisted-by: Gemini Fixes: https://tracker.ceph.com/issues/49958 Signed-off-by: Patrick Donnelly <[email protected]>
This introduces comprehensive test coverage for the newly implemented SQLite VFS to RADOS advisory lock state machine, verifying the atomic escalation paths and contention handling. Specific scenarios newly covered: - ConcurrentReaders: Verifies multiple clients can successfully hold SHARED locks simultaneously without blocking. - ReservedLockConcurrency: Ensures a RESERVED lock allows existing readers to continue while correctly preventing other immediate transactions. - ExclusiveLockConcurrency: Validates EXCLUSIVE locks correctly return -EBUSY to block incoming readers. - LockDowngrade: Validates locks correctly step down from EXCLUSIVE to SHARED after a transaction commits while a read cursor is still open. - DeadClientRecovery: Simulates a crashed writer by injecting a stale XATTR_EXCL and verifies the safe recovery and lock-stealing logic. - ContentionWaitLoop: Verifies the -EBUSY backoff/retry loop correctly waits for locks to free up before reaching the acquire_timeout. - LockRenewal: Confirms the background lock_keeper thread successfully renews both SHARED and EXCLUSIVE leases to prevent premature expiration. Assisted-by: Gemini Signed-off-by: Patrick Donnelly <[email protected]>
These are not part of any public ABI/API. Signed-off-by: Patrick Donnelly <[email protected]>
Which is apparently required by the sqlite3 busy_timeout. Previously, this was implemented (incorrectly) within the VFS SimpleRADOSStriper itself. Signed-off-by: Patrick Donnelly <[email protected]>
The wait is no longer done by the VFS layer (in general without a lock timeout pragma). Signed-off-by: Patrick Donnelly <[email protected]>
Signed-off-by: Patrick Donnelly <[email protected]>
Now that libcephsqlite implements xSleep and supports the SQLite busy handler, setting a 60-second (default) busy timeout allows mgr modules to wait out transient lock contention or lock recoveries rather than immediately aborting with SQLITE_BUSY. This duration safely exceeds SimpleRADOSStriper's 30-second lock_keeper_timeout. Signed-off-by: Patrick Donnelly <[email protected]>
|
This is an automated message by src/script/redmine-upkeep.py. I found one or more
The referenced tickets are: Those tickets do not reference this merged Pull Request. If this Pull Request merge resolves any of those tickets, please update the "Pull Request ID" field on each ticket. A future run of this script will appropriately update them. |
ceph/ceph#69199 escalates the cephsqlite striper lock with a write op ending in CMPXATTR, which sets rval = 1 on a true comparison. Classic zeroes that in PrimaryLogPG::execute_ctx() for any non-returnvec write, but crimson had the same clause in an else-if chain behind a may_read() branch, and CMPXATTR is __CEPH_OSD_OP(RD, ...), so the branch was never reached and the client got 1. Move the zeroing out of the chain. Signed-off-by: Matan Breizman <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
#69199 escalates the cephsqlite striper lock with a write op ending in CMPXATTR, which sets rval = 1 on a true comparison. Classic zeroes that in PrimaryLogPG::execute_ctx() for any non-returnvec write, but crimson had the same clause in an else-if chain behind a may_read() branch, and CMPXATTR is __CEPH_OSD_OP(RD, ...), so the branch was never reached and the client got 1. Move the zeroing out of the chain. Signed-off-by: Matan Breizman <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.