* feat: report a downgraded region's last entry once durable and roll back for skip-WAL rows A downgrade of a region whose manifest is published conditionally (writes require a lease and the WAL is the object store WAL) no longer flushes unless the memtable holds rows that are not in the WAL; the next leader recovers the rest from the source's WAL. A change to Follower reports the last entry id only once the WAL is durable through it. A downgrade reply now carries `has_skip_wal_writes` when the region may still hold rows outside the WAL after the downgrade; the metasrv then rolls the migration back instead of retrying or taking the region over, and aborts with that reason. An empty memtable left marked by a failed write no longer reports such rows. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: flush a downgrading region that skips the WAL and tighten tests A handover of a region whose options skip the WAL records no tail of its source, so a downgrade now flushes such a region even when its memtable holds only rows logged before the option changed. Tests cover that case, the metadata region's rows on the Noop WAL, a Follower change that waits without holding the worker and again on a region that is already a Follower, a flagged reply after an unflagged one in the same batch, the failure of a write that installs no row, and the abort reason of a failed candidate upgrade. Docs scope the meaning of a false `has_skip_wal_writes` and of the metadata region's flush. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: report logged rows of a region that skips the WAL and bound an abandoned downgrade A region whose options skip the WAL is handed over without a tail of its source, so its unflushed rows count as rows the next leader cannot recover from the WAL: `MitoRegion::has_skip_wal_writes` reports them and decides the downgrade's flush, so a follower that cannot flush them rolls the migration back. The datanode bounds each region's downgrade, the flush and the change to Follower together, by its flush timeout and replies with a retryable error past it. The task that waits for the WAL to be durable stops waiting once nobody waits for its reply, and a role change builds the durability barrier only for a Follower. Tests cover a follower whose options were made to skip the WAL, with and without rows, a downgrade timeout that releases the region, and a rollback of two requested regions; the abort reason of a failed candidate upgrade is compared exactly. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: refuse a handover to a candidate with stale skip-WAL options A candidate whose options skip the WAL commits an empty handover, which records no tail of its source. An ALTER during the migration reaches only the routed source, so a candidate can still skip the WAL while the source logs rows it does not flush. Such a handover now fails, committing nothing, when the source has unflushed WAL entries; the error is not retryable, since only closing the candidate after the rollback fixes its options. The datanode waits for a shared downgrade flush without its own timer, under the downgrade's single bound. Docs describe the rollback reason as rows the candidate may not recover from the WAL, and when a false flag can be trusted. Tests cover the refused handover and its recovery once the options match, a flagged reply carrying an error, and a downgrade timeout that waits until the durability wait is admitted. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: split the abandoned downgrade test and cover a deadline used up by the last attempt The datanode test of a timed-out downgrade no longer waits for the durability wait to be admitted, which raced the deadline; a Mito test drops the reply of a Follower change once its wait is admitted and checks that the region is released. A metasrv test covers a last downgrade attempt whose mailbox expiry uses up the procedure's time: the candidate upgrade then rolls the migration back without sending anything. The rollback test keeps a flagged success and a flagged error. Docs describe the skip-WAL predicate as rows the next leader may not recover, scope the durability comment to a Follower change, note that the metasrv must also understand the flag, and say why a refused handover is not retried. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: scope the mock leader to the downgrade deadline test Signed-off-by: jeremyhi <jiachun_feng@proton.me> * refactor: report only skip-WAL rows now that a handover records the source's tail A handover or takeover now records the source's tail even when the candidate's options skip the WAL, so the rows a region logged before its options turned skip_wal on are recovered from that tail. The downgrade flush and the flag therefore count only rows written without the WAL: every other row in the memtable is in the WAL up to the reported last entry, which the Follower change still waits to be durable whatever the region's options. Tests run the source through the graceful downgrade: rows logged before the option, with and without an earlier flush, reach a candidate by a handover or by a takeover after the report was lost; a candidate that a rolled-back migration left awaiting its Leader lease recovers the rows the source logged since; a downgrade under enqueued acknowledgement waits for those rows to be durable; and rows written while the WAL was skipped stay reported after the option is turned off again. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: release the region before the durability wait and tighten downgrade tests The task that changes a region to Follower finishes the work that needs the region, including the fencing notification, before it waits for the last entry to become durable, so a pending wait holds only the last entry id, the barrier and the reply. Tests check that a downgrade of an object store WAL region without write leases still flushes, that each setup role change succeeds, and that an abandoned wait is dropped, observed through the log store it holds. Docs state the durability barrier per provider. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: cover a mixed downgrade flush, the flag on a timed-out downgrade and its abort reason A downgrade's flush of logged and skip-WAL rows persists both, as a reopen without WAL replay shows. A downgrade that times out still reports the skip-WAL rows its region holds. The last downgrade attempt that uses up the deadline aborts as a failed candidate upgrade. The timeout reply is built in a match that rustfmt formats. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * docs: scope the downgrade flush skip and the reply fixture wording Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: let the only downgrade attempt use up the deadline Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: reply to a role change before the fencing notice unless a Follower waits for its WAL Only a successful change to Follower notifies, releases the region and waits for its WAL before it replies; every other outcome replies first, as before. Log the entry the wait is for and an abandoned wait, and describe the deadline test's lease as ending with the procedure's time. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: drop the retry interval the single-attempt deadline test never waits Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: reply to a Leader change before its sweep, and check the partial-flush handover's bound A successful change to Leader replies before it schedules the HDFS temp-file sweep, as before. The partial-flush handover case asserts that the source's flushed entry id is the first batch's last entry, strictly between zero and the final entry. The region server's skip-WAL accessor is crate-visible. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * docs: say which logged rows a handover and a takeover recover after a downgrade skips its flush Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: skip a retried downgrade's flush of a metric metadata region that is already a Follower A downgrade whose change to Follower timed out after the metadata region became a Follower is retried with a Downgrading flush, which failed on the metadata region because a Follower is not flushable, so every retry failed. The flush now skips that region; its handover still fails while it holds entries its manifest does not cover. Drop tests that decide no condition this change adds, and tighten doc wording. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * fix: flush a metric metadata Follower that still holds rows on a retried downgrade Skip the retried downgrade's flush of the metadata region only when it is a Follower whose memtables are empty; one that still holds rows gets the flush, which fails as before. Restore the check that a flagged downgrade reply decodes into the pre-field layout. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: check the reason first and fence the pair in the dirty metadata Follower test Read the metadata region's role and memtables only for a Downgrading flush. The dirty metadata Follower test sets the pair to DowngradingLeader through the metric engine, as the downgrade handler does, and checks that the flush fails on the Follower. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * test: check that only a downgrade's flush skips a flushed metadata Follower The clean retry first sends a flush without a reason, which still fails on the metadata Follower, then the downgrade's flush, which skips it. A shared helper changes a role and asserts that it succeeded. Signed-off-by: jeremyhi <jiachun_feng@proton.me> * style: address review nits on the downgrade reply and flush test Name the role states through SettableRegionRoleState instead of importing its variants, order the derives of DowngradeRegionReply as elsewhere in the file, and drop the comment that restates the role helper. Signed-off-by: jeremyhi <jiachun_feng@proton.me> --------- Signed-off-by: jeremyhi <jiachun_feng@proton.me>
Sqlness Test
Sqlness manual
Case file
Sqlness has two types of file:
.sql: test input, SQL only.result: expected test output, SQL and its results
.result is the output (execution result) file. If you see .result files is changed,
it means this test gets a different result and indicates it fails. You should
check change logs to solve the problem.
You only need to write test SQL in .sql file, and run the test.
Case organization
The root dir of input cases is tests/cases. It contains several subdirectories stand for different test
modes. E.g., standalone/ contains all the tests to run under greptimedb standalone start mode.
Under the first level of subdirectory (e.g. the cases/standalone), you can organize your cases as you like.
Sqlness walks through every file recursively and runs them.
Kafka WAL
Sqlness supports Kafka WAL. You can either provide a Kafka cluster or let sqlness to start one for you.
To run test with kafka, you need to pass the option -w kafka. If no other options are provided, sqlness will use conf/kafka-cluster.yml to start a Kafka cluster. This requires docker and docker-compose commands in your environment.
Otherwise, you can additionally pass the your existing kafka environment to sqlness with -k option. E.g.:
cargo sqlness bare -w kafka -k localhost:9092
In this case, sqlness will not start its own kafka cluster and the one you provided instead.
Run the test
Unlike other tests, this harness is in a binary target form. You can run it with:
cargo sqlness bare
It automatically finishes the following procedures: compile GreptimeDB, start it, grab tests and feed it to
the server, then collect and compare the results. You only need to check if the .result files are changed.
If not, congratulations, the test is passed 🥳!