From 62c4d267a6209da2d9dcd705d9bddfd2747ff187 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 26 Nov 2026 15:38:43 +0300 Subject: [PATCH 1/2] client: Flush the write-back cache before CAS writes with immediate_commit execute_cas() runs a SYNC before a CAS write over dirty write-back data only when the pool's immediate_commit is not "all". But the write-back cache also holds writes for immediate_commit=all pools, so there the CAS write went to the OSD first, succeeded against the old version, and the older cached write overwrote it at the next flush. Check enable_writeback here like the other write-back checks in cluster_client.cpp do. --- src/client/cluster_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index a67dca19..ddaf0949 100644 --- a/src/client/cluster_client.cpp +++ b/src/client/cluster_client.cpp @@ -925,7 +925,7 @@ void cluster_client_t::execute_cas(cluster_op_t *op, bool nosync) cb(op); return; } - if (!(op->flags & OP_IMMEDIATE_COMMIT) && !nosync && + if ((!(op->flags & OP_IMMEDIATE_COMMIT) || enable_writeback) && !nosync && wb->has_dirty(op->inode, op->offset, op->len)) { cluster_op_t *sync_op = new cluster_op_t; -- 2.47.3 From 67f2fe826c14283079db205bbccbba164882ac1e Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 26 Nov 2026 15:38:43 +0300 Subject: [PATCH 2/2] client: Delete written-back buffers with immediate_commit again 21066a09 deletes buffers in the flush callback when immediate_commit is on, because no SYNC ever removes them then. Since 2e223f03 a flush op carries its flush_id, so continue_rw() marks its buffers as written, with flush_id 0, before the callback runs, and delete_flush() finds nothing. The buffers then stay forever: memory grows with every range written, and reads are answered from them with version 0, so a CAS write retried after -EINTR never sees the real version. Skip mark_flush_written() for immediate_commit ops, as handle_op_part() already does for mark_flush_written_to(). Also run test_cas with IMMEDIATE_COMMIT=1. It fails without the previous commit ("CAS write data lost") and without this one ("read returned version 0"). --- .gitea/workflows/test.yml | 18 ++++++++++++++++++ src/client/cluster_client.cpp | 2 +- tests/run_tests.sh | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index ad781d0c..38c77787 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -113,6 +113,24 @@ jobs: echo "" done + test_cas_imm: + runs-on: ubuntu-latest + needs: build + container: ${{env.TEST_IMAGE}}:${{github.sha}} + steps: + - name: Run test + id: test + timeout-minutes: 3 + run: IMMEDIATE_COMMIT=1 /root/vitastor/tests/test_cas.sh + - name: Print logs + if: always() && steps.test.outcome == 'failure' + run: | + for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do + echo "-------- $i --------" + cat $i + echo "" + done + test_change_pg_count: runs-on: ubuntu-latest needs: build diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index ddaf0949..38e4e7ba 100644 --- a/src/client/cluster_client.cpp +++ b/src/client/cluster_client.cpp @@ -1322,7 +1322,7 @@ resume_2: op->retval = op->len / pool_cfg.bitmap_granularity; } } - if (op->flush_id) + if (op->flush_id && !(op->flags & OP_IMMEDIATE_COMMIT)) { wb->mark_flush_written(op->inode, op->offset, op->len, op->flush_id); } diff --git a/tests/run_tests.sh b/tests/run_tests.sh index caac41b7..28abe6ba 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -6,6 +6,7 @@ cd $(dirname $0) ./test_add_osd.sh ./test_cas.sh +IMMEDIATE_COMMIT=1 ./test_cas.sh ./test_change_pg_count.sh SCHEME=ec ./test_change_pg_count.sh -- 2.47.3